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(); } }
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.
Ctrl-Z puts cin in an error state, so cin.ignore does nowt. try cin.Clear () instead.
Source: https://habr.com/ru/post/975233/More articles:Java compare integer and bigInteger - javaSimulate the drag and drop effect of Windows in Winflow FlowLayoutPanel - c #While the loop causes an infinite loop, but I cannot understand why - c ++C # paint program flickering - c #Re-reading in EOF by stdin - c ++Change UITabBarItem Un-selected Color Tint - Swift - iosRecognize that the wizard is inactive - github-for-windowsBest way to remotely debug a C # mono application running on Linux with Visual Studio 2013 - c #Paste in Data.Set and check if the item exists at the same time - haskellAppEngine datastore timeout error reached before reaching 30 second limit - google-app-engineAll Articles