how can i end a while loop ??

Started by
11 comments, last by games_mylife10 18 years, 10 months ago
Hi I made this code, i want to (end-of-file) lol!!! i can't get out of this loop: i mean i press ^z and it still keep asking me to enter more !!! how ?? my problem is when i ask to enter texts .. i can't stop it! #include <iostream> using std::cout; using std::cin; using std::ios; using std::cerr; using std::endl; #include <fstream> using std::ofstream; #include <cstdlib> int main() { ofstream outlinefile("Line.dat", ios::out); if (!outlinefile) { cerr <<"file could not be opened"<<endl; exit(1); } cout << "Enter several lines of text: "<<endl << "Enter end-of-file to END input.\n?"; char text[1000]; while (cin.getline (text,1000)){ outlinefile <<text<<endl; cout<< "?"; } return 0; }
Advertisement
look at the break; statement.
oh i forgot to tell .. this is a C++ code .. im using Visual C++ "compiler"
As the AP said, break; is what you're looking for.
where do i type break;?? in the input?
oh, but i want from the user to enter several lines of texts !! when i used break; it got only one line of text!

thank you guys for helping me
combining his name, his location and

using std::cout;
using std::cin;
etc.

and

char text[1000];

I'd say he's kidding...
Quote:Original post by games_mylife10
i want to (end-of-file) lol!!!

I'd say he's 11 years old.
Isn't EOF ^d (CTRL-d) rather than ^z (CTRL-z)?

IIRC, CTRL-c is quit, CTRL-d is EOF, CTRL-z is background, CTRL-s is software flow control stop, CTRL-q is software flow control start...at least on 'nix. AFAIK it's just the normal ASCII set.
-- Jonathan
judging by his nick he is 10, lol.
How can we talk about the reason of our lives if we ourselves did not choose to live ?

This topic is closed to new replies.

Advertisement