谁能详细解释一下这个程序

问题描述

#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 变量打印到控制台。