【发布时间】:2021-02-26 11:41:54
【问题描述】:
#include <iostream>
using namespace std;
int main()
{
const int SIZE=4;
char Sentence[SIZE];
char Sentence2[SIZE];
cout << "Enter the sentence" <<endl;
cin >> Sentence;
cout << "\nThe string read with cin was"
<< endl <<Sentence <<endl;
char ch = cin.get();
cout << "Enter the second sentence: "<<endl;
cin.get(Sentence2,SIZE,'$');
cout << Sentence2 <<endl;
}
输出
Enter the sentence
This is my first sentence
The string read with cin was
This
Enter the second sentence:
is
我刚开始学习 C++,我无法理解这个程序以及它的输出。请任何人建议我从哪里学习或详细解释它。
【问题讨论】:
-
哪一部分不明白?
-
char大小为 4 的数组只能容纳 3 个字符,为空终止符留出空间。 -
这部分的输出我看不懂:cout
-
是的,你能解释一下吗
-
这并没有解决问题,但那是写得很糟糕的代码,所以你不需要花太多时间去理解它。