Menu

No Output / Program Does Not Run

Sam
2009-11-25
2012-09-26
  • Sam

    Sam - 2009-11-25

    Hi

    I am a new user to C++. My simple Hello world program does not output anything
    in the command window:

    // my first program in C++

    include <iostream></iostream>

    using namespace std;

    int main ()

    {

    cout << "Hello World!";

    system("Pause");

    return 0;

    }

    Compile Log:
    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Progs\first.cpp" -o "C:\Progs\first.exe" -pg -g3 -mwindows -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" -lgmon
    -pg -g3 -mwindows
    Execution terminated
    Compilation successful

    Can you advise me on why there is no Hello World! output in the command window
    please?

     
  • Sam

    Sam - 2009-11-25

    The directive #include is for the iostream file but this does not paste
    properly on the forum.

     
  • Wayne Keen

    Wayne Keen - 2009-11-25

    Thanks you for posting your log! Thwe answer is right there.

    -mwindows

    This indicates that you have told the compiler to compile Windows
    (GUI) code, but the code you are working with is console code. This will cause
    a console program to fail to output results.

    Wayne

     
  • cpns

    cpns - 2009-11-25

    The directive #include is for the iostream file but this does not paste
    properly on the forum.

    Sigh.

    Note:

    1. The row of buttons above the post composition box;
    2. The link below the box;
    3. The WYSIWYG "Preview" box below that.

    This is what you could have have had:

    // my first program in C++

    include <iostream></iostream>

    using namespace std;

    int main ()
    {
    cout << "Hello World!";
    system("Pause");
    return 0;
    }

    Build log:

    Compile Log:
    Compiler: Default compiler
    Executing g++.exe... g++.exe "C:\Progs\first.cpp" -o "C:\Progs\first.exe" -pg
    -g3 -mwindows
    -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" -lgmon -pg -g3 -mwindows
    Execution terminated
    Compilation successful

    For your further entertainment:
    [http://daringfireball.net/projects/markdown/syntax](http://daringfireball.n
    et/projects/markdown/syntax)
    http://www.codinghorror.com/blog/archives/001306.html
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.