Hi all,
I have tried to compile a program from the book C++: A Beginner's Guide by Herbert Schidt. The problem I encounter is when I try to run the program from the folder, that is the .exe file I believe located in: C:\Documents and Settings\Peter\My Documents\Visual Studio 2005\Projects\sample1\debug
This simply closes after opening. Am I running it from the correct location I can't find an executable file anywhere else in the sample 1 folder.
I believe it's a CLR project. I'm just wondering what I'm doing wrong. Thanks

Program closing right after opening
Guyus
#include <iostream>
using namespace std;
//A C++ program begins at main ().
int main()
{
cout << "C++ is power programming.";
return 0;
I have added the two strings, "#include <conio.h>" and "getch();" that you mentioned and yes, it works OK now. Thank You!
prativen_msft
Just out of curiosity...I had the same problem and after the build, it tells me I have a warning. It says that "getch ();" is depecrated. (Adding those two lines of code did fix the problem, just wondering what it means when it says it is deprecated). And also, does anyone know why I am not getting the, "Click any button to continue" line at the bottom of my program Here's the code I'm using.
tang.hz
Maybe its a console program. How do you run it
Try to open a command prompt and run it from there.
If you run it from the IDE try Strg+F5!
JD3
Just out of curiosity...I had the same problem and after the build, it tells me I have a warning. It says that "getch ();" is depecrated. (Adding those two lines of code did fix the problem, just wondering what it means when it says it is deprecated). And also, does anyone know why I am not getting the, "Click any button to continue" line at the bottom of my program Here's the code I'm using.
#include <iostream>
#include
<conio.h>int
main(){
std::cout <<
"Hello World!" << std::endl;getch();
return 0;}
// END main()xarmoso
maybe this is because all your program does is a simple Cout or something.... or shows a message. If thats what it is supposed to do, then it will not wait and close right after showing the message. one way to stop it is
#include <conio.h>
and then right before your main() function ends,
use...
getch();
this will require the user to enter a character on the keyboard before the program terminates.'
hope this helps.
e.g
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello world"<<endl;
getch();
return 0;
|}
Kevin Downs
add in this line to pause the system when writting console apps:
#include <iostream>
#include
<conio.h>int
main(){
std::cout <<
"Hello World!" << std::endl;// getch();
system (
"PAUSE"); // use this to pause the system where ever you want...... return 0;}
// END main()