linear-cpp icon indicating copy to clipboard operation
linear-cpp copied to clipboard

std::cin.eof()

Open okaoui opened this issue 5 years ago • 2 comments

Hi, I wasn't able to exit program in chapter 6, i keep typing numbers in the terminal but where end of file?

if(std::cin.eof()) { break; }

when it breaks?

okaoui avatar Feb 28 '19 22:02 okaoui

std::cin.eof() is first introduced in chapter 7. The comment above the while loop (starting line 39 of chapter 7) explains how this is used to break out of the loop. Here is the comment:

We could use much the same implementation as we used in the last examples, which assumes that if the input failed, there is nothing more to read. However, let's be a little more thorough and insist that the user keep entering data until he closes the stream. If a file is being redirected this will happen when the end of the file is reached; when entering data directly, Control-D will do the job on Linux, while Control-Z will work on Windows.

If you supply the program with a file, then the loop will end when it reaches the end of the file. When you type numbers through the terminal, you have to send the end of file (eof) value yourself. Control-Z in Windows and Control-D in Unix systems will send the eof value to the program, which will end the loop.

MarkHarder avatar Feb 28 '19 23:02 MarkHarder

std::cin.eof() is first introduced in chapter 7. The comment above the while loop (starting line 39 of chapter 7) explains how this is used to break out of the loop. Here is the comment:

We could use much the same implementation as we used in the last examples, which assumes that if the input failed, there is nothing more to read. However, let's be a little more thorough and insist that the user keep entering data until he closes the stream. If a file is being redirected this will happen when the end of the file is reached; when entering data directly, Control-D will do the job on Linux, while Control-Z will work on Windows.

If you supply the program with a file, then the loop will end when it reaches the end of the file. When you type numbers through the terminal, you have to send the end of file (eof) value yourself. Control-Z in Windows and Control-D in Unix systems will send the eof value to the program, which will end the loop.

OK thanks. By the way it's a great tutorial, well done! Do you have some examples for interacting with database e.g. PLSQL, calling sql packages...

okaoui avatar Mar 03 '19 10:03 okaoui