visual C++

I tried to program on Visual C++ and it says, did you forget #include. I tried using #include and it is giving a warning and an error for cout<<" ";. Can somebody please write a short code for this compiler header. What are the other alternatives to make this program work?




  • The [italic]cout[/italic] error might be because you aren't taking the namespace issues into account. You need to make sure that in some way you tell the compiler that you are using the [italic]cout[/italic] stream that's a part of the [italic]std namespace[/italic]. There are 3 ways this is typically done:



    std::cout << ...


    #include <iostream>
    using std::cout;

    cout << ...


    #include <iostream>
    using namespace std;


    cout << ...[/code]
    The first method is generally preferred by the more experienced coders and the last one used most often in smaller projects and by beginners.

    As for the stdafx thing, what type of project are you creating - Win32 Application/Win32 Console Application/etc...? I'm personally of the opinion that dealing with pre-compiled headers is mostly a pain-in-the-$#@. Whenever I create a project, whatever type it is, I always select "empty project" from the wizard. Choosing other options always seems to force you to have that stdafx piece in there.
  • I found out by writing #include and sfter that #include in that order the program works.

    using namespace std;

    int main()
    cout<<"Hello world!

    works fine.

    If you have anymore variations please write!!!

  • When using precompiled headers, StdAfx.h has to be included in all source files and as the first statement within every source file. Precompiled headers can be turned off in the project property pages, it just makes compilation a little slower if you have many source files and use many headers (such as the Windows SDK).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!