Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::cin.eof() #6

Open
okaoui opened this issue Feb 28, 2019 · 2 comments
Open

std::cin.eof() #6

okaoui opened this issue Feb 28, 2019 · 2 comments

Comments

@okaoui
Copy link

okaoui commented Feb 28, 2019

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?

@MarkHarder
Copy link
Contributor

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.

@okaoui
Copy link
Author

okaoui commented Mar 3, 2019

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants