Build + Compile "Hello World" Program with Visual C++ 2005 beta

I am not able to build and compile a primitive "Hello World" Program with Visual C++ 2005 beta. Although I have been searching the Internet for 2 hours, I have not found any solution, but I hope there is anybody out there who is able to create projects in Visual C++ 2005 beta

My program is:

#include <stdafx.h>
#include <iostream.h>
void main()
{
            cout << “Hello World!” << endl;
}

The error message is (td-test is my project name):
fatal error C1083: Cannot open precompiled header file: 'Debug\td-test.pch': No such file or directory

If I omit the line '#include <stdafx.h>', the error is:
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source

If I choose "not using precompiled headers" in td-property pages, the error is:
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory

If I delete the line "#include <stdafx.h>", the same error occurs with 'iostream.h' instead of 'stdafx.h'

Adding an #include <stdio.h> does not help and does not change anything.

Does anyone have an idea how to create a primitive project that allows me to work with Visual C++ 2005 beta Does anyone see a solution

Thank you a whole lot in advance!!


Answer this question

Build + Compile "Hello World" Program with Visual C++ 2005 beta

  • Tom S

    Thanks, Ayman!

    Thanks for your help and also for the links. When using your implementation (with iostream and using namespace std), the error no longer occurs!! But there is another error:
    "Linking...
    MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup"


  • tizza2k

     Ayman Shoukry wrote:
    That is correct. Thanks for the more details Ritz!

    Thanks,
      Ayman Shoukry
      VC++ Team
    I wasn't trying to demerit your post if it seemed that way. As you said, just give it some more detail.

  • Brad Pitcher

    That is correct. Thanks for the more details Ritz!

    Thanks,
      Ayman Shoukry
      VC++ Team


  • JohnI

    You can create a "Hello World!" application using the following steps:

    1) Open Visual C++
    2) Select File -> New -> Project (the project types dialogue will open)
    3) Select Visual C++ on the left and Win32 Console Application on the right
    4) Name your project Hello and then click "OK"
    5) The "overview" dialogue will open, just click "Next >"
    6) The "Application Settings" dialogue will open
       a) Under "Application type:" make sure "console application" is selected
       b) Under "Additional options:" make sure "empty project" is selected
       c) Click "Finish" (and you should have a new project opened)

    7) From the menu bar, select Project -> Add New Item (the Add New Item dialogue will open)
    8) Select Visual C++ on the left and C++ File (.cpp) on the right
    9) Name your file Hello and then click "Add"
    10) Type into the editor the following program:

    // Simple Hello World Console Application
    #include <iostream>
    using namespace std;
    int main()
    {
         cout << "Hello World!" << endl;
         return 0;
    }


    11) Save your project
    12) From the menu bar, select Build -> Build Hello (and your app should start compiling)

    Now you can open a DOS window change your directory path to where hello.exe is and then type hello. It works for me. This is the same method used in most Visual C++ "How To..." books.


  • sdmeijer


    helppp
    i'm also having the same kind of problem.. i have removed all".h"'s from the files and put using namespace std; but still i'm having the same kinda problem ....
    help guys

  • Localrob2

    Try


    class
    ="txt4"> #include <iostream>
    int main()
    {
        std::cout << “Hello World!” << endl;
        return 0;
    }

     



    [edit] The "
    class="txt4">" is a bug. I reported it.

  • JJM88

    The header file is actually <iostream> without the ".h". Also, you need to use "namespace std".

    Change to "not using precompiled headers" and change you code to be something like:
    #include <iostream>
    using namespace std;
    void main()
    {
                cout << "Hello World!" << endl;
    }

    check out the following links for more details:
    http://msdn2.microsoft.com/library/zh80x809(en-us,vs.80).aspx
    http://msdn2.microsoft.com/library/71t65ya2(en-us,vs.80).aspx

    Also, see http://msdn2.microsoft.com/library/3dxawkbx(en-us,vs.80).aspx for using precompiled headers in projects (PCH).

    Hope this helps!

    Thanks,
      Ayman Shoukry
      VC++ Team.



  • pqjr

    Hi!!

    Thanks a lot for your advice. Unfortunately, it does not work, either, and the errors are still the same as reported above.

  • Hibernating Bear

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

    int main()

    {

    cout << "Hello World" ;

    return 0;

    }




  • nikitaj

    No problem at all RITZ, I absolutely understood what you meant, more details is always better in such cases.

    Thanks,
      Ayman Shoukry
      VC++ Team.

  • hearn

    You are probably not using a Win32 console application (which is what you need).

    Check out your build log, you might be using the linker switch  /subsystem:windows, if you are going to use /subsystem:windows then you need to implement your own WinMain (not main). If you are using just "main" then you need to use a win32 console application (subsytem:console).

    See this past post that deals with the same issue:
    http://forums.microsoft.com/msdn/ShowPost.aspx PostID=65052

    Thanks,
      Ayman Shoukry
      VC++ Team.

  • Matt Connolly

    What errors are you seeing

    Thanks,
      Ayman Shoukry
      VC++ Team

  • DNA5122

     Ayman Shoukry wrote:
    The header file is actually <iostream> without the ".h". Also, you need to use "namespace std".

    Well, as not to confuse the OPer you do not need using namespace std. You merely have to denote the standard namespace for your call to cout wich can be done by prefixing the namespace in the call or to put 'using namespace std;' before hand to ignore the std namespace. In C++ standard headers do not have the .h extension as apposed to C.

  • alexlim8190

    There is an obscure note regarding the directory paths in 2005 Beta.  It basically says you have to manually edit some files to properly point to the Windows Platform SDK, where all the includes and such are.

    I just went through this, and then again to be able to use the DirectX9 goodies.

    The URL for explaining this is: http://lab.msdn.microsoft.com/express/visualc/usingpsdk/default.aspx

    The Windows Platform SDK must also be downloaded and installed, and there is an internal registration between VC++ and the Platform SDK.

    Note that when editing the config file for the directory inlcludes and such that you need to make sure you are editing the EXPRESS version of the config file, as described in the MS article at the link above. 

    By the way, the reason for all of the requisite editing and all is that the Beta 2 version does not have a functioning edit dialog box for editing the directories.  There is a note to that effect in the article.

    contact me at robert.bone@ssa.gov.removethis if you need additional help.  I just spent a long time getting all of this stuff waded through and working (as of today), but at least I am ready to try my hand at cleaning up the #(*# examples from the two books I got that don't compile/link cleanly.  GGGRRRR

    Anyways, I hope all of this helps.

    Bob Bone


  • Build + Compile "Hello World" Program with Visual C++ 2005 beta