It was my bad. cin.ignore is very picky and doesn't work in certain situations. cin.get and cin.ignore both don't seem to work after taking input through cin. I think you have to flush the buffer, but you're new, so I don't want to confuse you.
Don't get in the habit of doing this, but until I get back to you on a better way to pause, use this...
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <conio.h>
int main()
{
cout << "Hello, world!" << endl;
cout << "Press Enter to continue...";
_getch();
return 0;
}
|
I say not to get in the habit of this because "conio.h" is not portable.
As far as the cin.ignore command goes, let me break it down for you.
cin.ignore() = Command used to ignore the characters specified until the second parameter is input. For example:
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
cout << "Hello, world!";
cin.ignore(50, '\n');
return 0;
}
|
This will print "Hello, world!" and then cin.ignore will ignore the next 50 characters that are input or wait for a newline character (pressing the Enter key.)
numeric_limits<streamsize>::max() will return the value of the maximum amount of characters that the input stream can hold (someone correct me on this if I'm wrong)
So... cin.ignore(numeric_limits<streamsize>::max(), '\n'); will ignore the maximum amount of characters you can input into the input buffer, or wait for a newline character. This is supposed to be a very good way to pause the console, but like cin.get, if you have previously input data into the input buffer, it will not work. You need to clear the buffer (I'll post some code later)
Alternatively, you could just run your programs from the command line.
You're not frustrating me. Just don't become one of those people who asks the forum members to do his homework assignments for him, if you know what I mean.