本帖最後由 tonyh 於 2022-12-8 19:44 編輯
- #include<bits/stdc++.h>
- using namespace std;
- string str;
- int main()
- {
- cin.tie(0);
- cin.sync_with_stdio(0);
- getline(cin, str);
- cout<<str<<endl;
- cout<<str.size()<<endl;
- cout<<str[1]<<endl;
- cout<<str[3]<<endl;
- return 0;
- }
複製代碼- #include<iostream>
- #include<cstdlib>
- #include<string>
- using namespace std;
- int main()
- {
- string str;
- cout<<"請輸入一字串(包含空白): ";
- getline(cin,str);
- cout<<"您剛輸入的字串是: "<<str<<endl;
- system("pause");
- return 0;
- }
複製代碼 |