Can someone explain to me how cin.get() works below. My thinking is that cin.get() takes in a character from the keyboard, assigns it to character1, compares it to EOF, if it is not equal, it takes in another character, assigns it to characer1, compares it to EOF, and the process goes on untill EOF is entered. Therefore, I expected character1 to have the last character entered (EOF) and I expected that last character to have been printed. This does not happen. It takes in characters until I press EOF and then it instead prints those characters. What is happening?
int character1;
cout << "Before input, cin.eof() is " << cin.eof()<< endl
<< "Enter a sentence followed by end-of-file:" << endl;
while ((character1 = cin.get()) != EOF)
cout.put(character1);
cout << "\nEOF in this system is: " << character << endl;
Aucun commentaire:
Enregistrer un commentaire