Stays in loop, but it's not an infinite loop...
Also, cin.get(char) is an I/O blocking function, meaning that if the input stream (cin) is empty, which it is after "hello" has been processed, the function waits for user input, essentially "blocking" the program from continuing until some input arrives in the stream. In your case, you want to input end-of-file to terminate the loop.
Alternatively, you could run it with the standard input redirected from a file via the command line. Assume you compile "counter.exe": make a text file "test.txt" with test input, and then run the program -
C:\path\to\exe>counter < test.txt
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement