other options for system()

I read that system() was bad to use. Then what should I do if I want the person to hit a key to continue?
(instead of: system("PAUSE"))
Console.ReadKey() or cin.ignore()


1
2
3
4
5
Console.WriteLine("Press Any Key to Continue...");
Console.ReadKey();

std::cout<<"Press Another Key";
std::cin.ignore();

Last edited on
I use getchar() from the conio.h library.

Example:

1
2
3
4
5
6
7
8
9
#include <conio.h>
#include <iostream>

int main() {
using namespace std;
cout << "Hello World" << endl;
getchar();
return 0;
}
for console.readkey() it said that i needed to include something.
and neither cin.ignore() or getchar() worked.
instead of pausing to wait for a key to be pressed it just kept going.
You probably did something like this then:

1
2
int x;
std::cin>>x;


The problem is that that leaves junk in the input buffer. (A newline to be exact) You'll need to remove it before you can pause the console with std::cin.ignore();.
well how do i remove it then?
even though i dont think i did anything like that.
std::cin.sync() will flush the input stream.
Topic archived. No new replies allowed.