#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);那一行的时候要按下两次回车?