- #include<iostream>
- #include<cstdlib>
- #include<string>
- using namespace std;
- int main()
- {
- string str;
- cout<<"輸入一字串: ";
- getline(cin,str);
- cout<<"本字串的長度為"<<str.length()<<"個字元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼- #include<iostream>
- #include<cstdlib>
- #include<string>
- using namespace std;
- int main()
- {
- string str;
- cout<<"輸入一字串: ";
- getline(cin,str);
- cout<<"本字串的長度為"<<str.size()<<"個字元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |