Re: [Dev-C++] A very singular problem in Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jonathan W. <jon...@gm...> - 2007-04-02 09:50:37
|
Indeed, system('pause') is rather messy (plus it's not really portable)
I usually do a system('pause') as a quick fix in the early stages of setting
up a program, I guess I'll use cin.get() from now on :)
This would make the program so:
#include <iostream>
using namespace std;
int main()
{
//say hello :)
cout<<"Hello World!\n";
//wait for user keypress
int pressed = cin.get();
//ignores an extra keypress
cin.ignore();
/*
do some more things here
*/
}
But why should I ignore an extra character in the input, since the cin.get()
will eat the key the user pressed?
could it be a '\n' vs. '\r\n' issue ?
Jonathan
On 4/2/07, Amy...@ao... <Amy...@ao...> wrote:
>
> you really should not use system calls in a program unless you really
> need it. They are unsafe, and it sort of gets the OS to do the work for you.
> It is always safer and better practice to use cin.get() instead of
> system("pause")
>
> Yiu can add cin.ignore() under cin.get() if you use cin in the program as
> an input object, but not all compilers need this, the mingw one does however
>
|