jock1092

Honorable
Jan 17, 2013
5
0
10,520
i have recently decided to try learning some basics of c++ programming using "cplusplus.com" tutorials.

however when i try to run "hello world!.cpp" in dev c++ it stops executing the file instantly.

here is the compile log
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Users\Josh\Documents\hello.cpp" -o "C:\Users\Josh\Documents\hello.exe" -ansi -traditional-cpp -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
Execution terminated

and the source code is
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0 ;
}

am i doing something wrong? i am a total noob at this so it probably obvious to anyone who knows this stuff but any help would be much appreciated
 

Flame Soulis

Honorable
May 11, 2013
4
0
10,510
This is because the program executes very few commands. When you are doing cout, you are doing the equal to the batch file command, echo. Since the program is an executable, load up the command prompt manually (Short cut: Ctrl+R (brings up run window), type in cmd) and drag the exe it made (should be hello.exe in your documents folder) to the command prompt window. It should fill in the whole location of the file in quotes. Hit enter and you should see "Hello World" appear in the prompt.

To break it down, whenever you launch a command line program, it will close the prompt once the program finishes. Since the program Hello World only does two things (print something on screen and exit respectively), it happens so fast it appears to be not working, but rest assured that it is working just the way it is supposed to.