C++ Build Failure

I get stuck on the easiest of codes, the "Hello World!" code. What I do, is start a Visual C++ Win32 Console Application, Empty Project... And Application Type Console Application.

Then, I add a file to the Source Files called HelloWorld.cpp. This is my code I type:

#include <iostream>

main()
{
std::cout << "Hello World!" << std::endl;
}


Then I try to build, compile, anything, but I keep getting this error saying:

c:\documents and settings\nick davidson\desktop\experiments\vbprojects\helloworld \helloworld\helloworld\helloworld.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I even added "return 0;" to that code but no luck, someone help me.




Answer this question

C++ Build Failure

  • Mark Stutzbach

    Ok, adding "void" worked, but when I build, the window comes up and actually says "Hello World!" like it's supposed to but, it never stays open, it opens and closes itself in super light speed.  Anyway to prevent that

    Edit: it works through command prompt ok, but I want it to work by clicking or debugging too...


  • tjokiest

    You can just step into your code using the debugger (F10) or you can just add system("Pause"); at the end of your main to prevent the window from closing quickly under the IDE.

    Hope this helps!

    Thanks,
    Ayman Shoukry
    VC++ Team


  • pire

    try -

    #include <iostream>

    void main()
    {
    std::cout << "Hello World!" << std::endl;
    }



  • Frank Jona

    You could use void main as someone suggested, but make sure you read this :-

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccelng/htm/basic_21.asp

    xZippy wrote:
    I get stuck on the easiest of codes, the "Hello World!" code. What I do, is start a Visual C++ Win32 Console Application, Empty Project... And Application Type Console Application.

    Then, I add a file to the Source Files called HelloWorld.cpp. This is my code I type:

    #include <iostream>

    main()
    {
    std::cout << "Hello World!" << std::endl;
    }


    Then I try to build, compile, anything, but I keep getting this error saying:

    c:\documents and settings\nick davidson\desktop\experiments\vbprojects\helloworld \helloworld\helloworld\helloworld.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    I even added "return 0;" to that code but no luck, someone help me.



  • brendon.smith

    I compile alot from command line or build file:

    cl hw.cpp /EHs|more

    Try this code, and see if it gets you started . . .

    // The hw.cpp program

    #include <iostream>

    using namespace std;

    int main()
    {
    char wait;
    cout << "Perfunctory \"Hello World\" message" << endl;
    cin >> wait; // type a letter and hit 'Enter'
    }


  • C++ Build Failure