|
From: Ioannis V. <no...@ya...> - 2002-02-11 23:28:21
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of aar...@ut... > Sent: Monday, February 11, 2002 10:28 PM > To: dev...@li... > Subject: [Dev-C++] Dev C++ Question > > > Hello... > > I have a question about closing a terminal window during a > C++ program > execution. I am using Dev C++ 4.01 as my compiler. At > http://www.cprogramming.com/close.html, it says that > inserting the line > cin.get() before the return 0 line will keep the terminal window open > until I press enter. This I find is true for the following program: > > #include <iostream.h> > int main() > { > cout<<"The Compiler Works"; > cin.get() > return 0; > } > > > However for the following code, I type my number, press > enter, and the window > closes immediately. Why doesn't the compiler display "You > entered: ", then my > number, and then close the terminal window once I push enter > (which would be > the second time)?? Am I putting the cin.get() statement in > the wrong spot?? Check out the code I'm using. > > #include <iostream.h> > int main() > { > int thisisanumber; > cout<<"Please enter a number:"; > cin>>thisisanumber; > cout<<"You entered: "<<thisisanumber; > cin.get() > return 0; > } > > I'm stuck, and I'm trying to teach myself C++. Your help is greatly > appreciated. After the cin>>this number; the '\n' remains in the stream and is picked by the next cin.get(). If you want to pause you must enter 2 cin.get(): #include <iostream> int main() { using namespace std; int thisisanumber; cout<<"Please enter a number:"; cin>>thisisanumber; cin.get(); cout<<"You entered: "<<thisisanumber; cin.get(); return 0; } Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.d2g.com * Alternative URL: http://run.to/noicys |