#include
#include
#include
int main()
{
using namespace std;
char charr[20];
string str;
cout << "Length of string in charr befor input: "
<< strlen(charr) << endl;
cout << "Length of string in str befor input: "
<< str.size() << endl;
cout << "Enter a line of text:\n";
cin.getline(charr,20);
cout << "You enter : " << charr << endl;
cout << "Enter another line of text:\n";
getline(cin,str);
cout << "You enter: " << str << endl;
cout << "Length of string in charr after input: "
<< strlen(charr) << endl;
cout << "Length of string in str after input: "
<< str.size() << endl;
return 0;
}
為什麼到了 getline(cin,str);那一行的時候要按下兩次回車?
復制你的代碼用我的VS2005運行,只要一次回車就出結果了,你用的什麼編譯運行?