I'm writting (have pretty much finished it now) a console program that takes two sentences works out the difference between them and applies those changes to each line of a file. What i would like to know is:
1) When i run my program through my IDE (codewarrior) once the program has finished the dos console stays open untill a key is pressed, if however the program is run straight from its .exe icon the console instantly closes as soon as the program has finished. Since i want the user to be able to read error messages i was wondering if anyone could tell me a line of code that will make the program wait for a key to be pressed before closing the console even when run from it's .exe icon.
2) I have the user enter a string of numbers followed by a character those numbers are stored in a vector<int>, the code i'm using is:
where i is an int and spaces is a vector<int>. This works fine but seems clumsy, is there a simple way for me to have the user enter numbers (all on one line separated by spaces) into a vector<int> without asking him to finish off with a character?
while (cin >> i)
3) I ask the user a series of yes and no questions where they reply with either 'Y' or another character, currently i'm just using
where c is a character, thing is if they type in "YY" to the first question by mistake the second question catches the second Y. Is there a way to avoid this other than using fgets()? IE. Is there some way i can flush the input stream after the first question is answered so i lose the second character?
Thanks in advance for any help provided :)
3/cout << flush;
I realise i can just use getch() (and i probably will) but i was wondering what the IDE does, since when I run it through the IDE the text telling the user to press a key to terminate the app appears in the border of the dos console.
cin.clear() does not work, it merely removes any error status from the input stream. I will try cout << flush but i presummed that would flush the output buffer, and i didn't think that my extra characters were in that buffer.... but you may be right, i'll try it out.
Thanks for the advice.
2) In this case a sentinel value is just fine.
Thanks prelude cin.ignore() was exactly what i wanted :), and whilst i'm still puzzled at what my IDE is doing, cin.get() works fine :)
Ok. where do you read about all these functions?
Google. Search the forums. Think :)