#include <iostream>
using namespace std;
int main ()
{
char ch[20];
cout << "enter a sentence:" << endl;
cin >> ch;
cout << 1 << ':' << ch << endl;
cin.getline (ch, 20, '/');
cout << 2 << ':' << ch << endl;
cin.getline (ch, 20);
cout << 3 << ':' << ch << endl;
return 0;
}
当在键盘上输入:"I like C++./I study C++./I am happy."的时候,为何结果是:
1:I
2: like c++. 这一行输出的结果为何不是I like C++./I study(19个字符)
3:I study c++./I am h 此结果为何不和上一行一样?默认情况下cin.getline(ch,20,'/')和cin.getline(ch,20)等价