View Full Version : How do I get it to stay on screen
albear
Aug 5, 2007, 01:35 PM
OK, I've written this programme and I've compiled it but when I run it I enter some numbers and words then I have to press enter to get there but as soon as it displays it it closes how can I make it so it doesn't do that
albear
Aug 5, 2007, 03:37 PM
Hello
albear
Aug 6, 2007, 08:09 AM
Anybody there
asterisk_man
Aug 6, 2007, 09:47 AM
At the end of your code output something like "press enter to quit" and then read in one more character. This way you'll wait for the user to do something before the program terminates.
albear
Aug 6, 2007, 03:58 PM
I've tried that but it still closes after I put my information in then press enter to continue but it just goes dtraight to the end of the programme then closes in an instant
asterisk_man
Aug 6, 2007, 05:55 PM
No, put the "press enter to continue" as the very last thing in main()
albear
Aug 7, 2007, 03:37 PM
I put a code in which I was told coded for that just before the Return 0, could you give me an example of the code you mean
albear
Aug 8, 2007, 02:32 PM
This is the bit I put it
Cout << "Press Enter to exit";
Cin.ignore(std::cin.rdbuf()->in_avail() + 1);
albear
Aug 10, 2007, 07:00 AM
Any advice would be great
asterisk_man
Aug 10, 2007, 05:45 PM
I'm not sure what it is you're trying to do with the second line you listed. I've not used iostream in a while but I think something like this will work:
char junk;
cout << "Press Enter to exit" << endl;
cin >> junk;
albear
Aug 11, 2007, 07:36 AM
i'm not sure what it is you're trying to do with the second line you listed. i've not used iostream in a while but i think something like this will work:
char junk;
cout << "Press Enter to exit" << endl;
cin >> junk;
OK it stays on screen after I put the information in but it doesn't close after I press enter, the line that you said you wernt sure on it has that line in the book and its worked before to make my text stay on screen
asterisk_man
Aug 14, 2007, 06:20 AM
If you're really stumped you can always fall back on plain c and use stdio.h
getchar();
Nosnosna
Aug 14, 2007, 06:35 PM
Cin >> tempchar; will only work if you actually give it a character to read... just pressing return won't advance the program.
If, instead, you use cin.get(tempchar); it will behave the way you want.