Sorry for the un-detailed title, but I couldn't think of a good way to describe this.
So I'm writing this program, and I have a pre-processor command to define a program end (so I can stop using system("PAUSE");, even though I'm just doing simple homework stuff, I'm trying to get into the habit of not using it for the future):
#define end cout<<"Press any key to continue..."<<endl; cin.ignore(numeric_limits<streamsize>::max(),'\n');
There's probably some reason why that's a bad idea, and if there is, feel free to tell me, I'm trying to learn here. Anyways, onto the point, so far it's worked fine for me, just ending my programs with:
However, in this program I'm working on, well, I'll throw some lines out there:
1 2 3
|
int counter;
cout<<"How many lines of data do you plan to input?"<<endl;
cin>>counter;
|
From there, the program just ends there, it doesn't run "end;", but if I put, "system("PAUSE");" it will run that. To further experiment, I tried this:
1 2 3 4 5
|
string counterStr;
int counter;
cout<<"How many lines of data do you plan to input?"<<endl;
getline(cin,counterStr);
streamline(counterStr)>>counter;
|
And when I did that, it would run the "end;" just fine.
To further test it, I tried it with cin instead of getline, and instead of "end;" I put:
cin.ignore(numeric_limits<streamsize>::max(),'\n')
At the end of my code, but it would skip that too.
So basically, why can't I get my program to pause properly at the end with cin?