Continue reading from iostream :: cin after Ctrl + Z (EOF)? (ignore does not work)

Why does the outer loop in the next program end when we provide only ctrl + z for the inner loop?

#include<iostream> int main() { string s1,s2; while(cin >> s1) { cout<<"In loop1\n"; while(cin>>s2) cout<<"In loop 2\n"; cin.ignore(); } } 
+4
source share
2 answers

Pressing Ctrl + z (on Windows) closes the standard input stream. Once it is closed, it remains closed. It does not magically open again after the completion of the inner loop. There simply are no reasons why this would be.

+7
source

Ctrl-Z puts cin in an error state, so cin.ignore does nowt. try cin.Clear () instead.

+3
source

Source: https://habr.com/ru/post/975233/


All Articles