在这个程序中
#include <iostream>
using namespace std;
int main()
{
const int SIZE=4;
char Sentence[SIZE];
cout << "Enter the sentence" <<endl;
cin >> Sentence;
cout << "n The string read with cin was"
<< endl <<Sentence <<endl;
char ch = cin.get();
}
我无法理解我们在cout << "n The string read with cin was" << endl <<Sentence <<endl;
之后使用ch =cin.get()
,所以为什么在输出中我只得到流的第一个字符。我应该得到整个输入句子,因为我最后使用了ch=cin.get(),所以它应该没有任何效果。谁能给我解释一下这个?
因为char只需要1个字符;-)所以你把cin.get()赋值给char,结果你有1个字符:-)