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
|  | 
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
Hello
Anybody there
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.
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
No, put the "press enter to continue" as the very last thing in main()
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
This is the bit I put it
Cout << "Press Enter to exit";
Cin.ignore(std::cin.rdbuf()->in_avail() + 1);
Any advice would be great
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:
Code: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 screenQuote:
Originally Posted by asterisk_man
If you're really stumped you can always fall back on plain c and use stdio.h
Code:getchar();
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.
| All times are GMT -7. The time now is 05:20 PM. |