如何解决谁能详细解释一下这个程序
#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++,我无法理解这个程序及其输出。请任何人都可以建议我从哪里学习或详细解释。
解决方法
cout << "Enter the second sentence: "<<endl;
将 Enter the second sentence:
打印到控制台。
cin.get(Sentence2,SIZE,'$');
最多读取 SIZE - 1
个字符,或者直到从控制台到 $
数组的第一个 Sentence2
字符(包括空格字符。为零终止符保留的 1 个字符)。>
cout << Sentence2 <<endl;
将 Sentence2
变量打印到控制台。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。