Sign in to follow this  

how can i end a while loop ??

This topic is 4586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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; }

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
combining his name, his location and

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

and

char text[1000];

I'd say he's kidding...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
combining his name, his location and

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

and

char text[1000];

I'd say he's kidding...

You do know Bahrain is a real place, right?

In my tests, ^z works just fine. It has to be at the begining of the line, though, or it gets confused.

Enter several lines of text:
Enter end-of-file to END input.
?Line One
?Line Two
?^Z


"Line One" and "Line Two" get written to the file, and then the program ends.

CM

Share this post


Link to post
Share on other sites
Hello !!

Thank you verrrrrrrry much~~~!!!!
it worked for me , i don't know what happened yesterday!! today it worked with ctrl+z ..

sorry about my stupid question but i'm a beginner and i'm not good in programming.. i'm trying my best to get better i hope!

and i'm really from Bahrain.. even when i was regestering in this forums .. i choose Bahrain and then a list of bahrain's cities appeared too !! :D


thank you again for the help!

Share this post


Link to post
Share on other sites

This topic is 4586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this