I teach C ++. I want to figure out how I / O works in the console. Already realized that if you type in cin
words through space / tabulation, it reads them through this given delimiter and prints to cout
. For example, I enter "hello man"
, - displays "helloman"
. This is normal, everything is clear. I also found out that CTRL+Z
halts the process and means the symbol of the end files when reading. I press ctrl+Z
(I don’t enter symbols before) and the process ends.
Question 1 : why, if I enter, for example, "hello ^Z"
(I entered ^Z
with the keyboard shortcut instead of manually first ^, then Z), then hello
first appears in the output stream, and nothing appears behind it, only if you press enter, a question mark appears in the box! (what is it all about?)
Question 2 : If then cin
reads characters through delimiters, then why didn’t it consider hello
first, then ^ Z and, according to the command, did not complete the process, reading the end-of-file character, as it is called in the Stroustrup book. Explain, please.
int main() { string current; while(cin>>current){ cout << current; } }