#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;
}
OUTPUT
Enter the sentence
This is my first sentence
The string read with cin was
This
Enter the second sentence:
is
I have just started learning C++ and I am not able to understand this program as well as it's output. Pls can anyone suggest me where to learn it from or explain it in detail.
cout << "Enter the second sentence: "<<endl;
Prints Enter the second sentence:
to the console.
cin.get(Sentence2,SIZE,'$');
Reads up to SIZE - 1
number of characters, or until the first $
character from console to Sentence2
array (including space characters. 1 character reserved for the zero terminator).
cout << Sentence2 <<endl;
Prints Sentence2
variable to console.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.