|
From: <gi...@li...> - 2002-02-13 17:37:27
|
Hello Aaron,
since you are developing console applications, my suggestion is: run them
from the console. In fact, when you use the console, there is no need to
add "cin.get" or "system("PAUSE")" or any other special instruction
preventing Windows from closing the window :-)
For instance, the following code would work as expected:
#include <iostream>
int
main()
{
std::cout << "Please enter a number:";
int n;
std::cin >> n;
std::cout << "You entered: "<< n << '\n';
}
At 13:43 12/02/02 -0500, Aaron wrote:
>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.
>
>Sincerly,
>Aaron
--
gisan
gi...@li...
|