Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

visual C++

philshellphilshell Posts: 5Member
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?

Thanks

Shelley

Comments

  • HK_MP5KPDWHK_MP5KPDW Posts: 770Member ✭✭✭
    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:
    [code]#1

    #include

    ...

    std::cout << ...

    #2

    #include <iostream>
    using std::cout;
    ...

    cout << ...

    #3

    #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.
  • philshellphilshell Posts: 5Member
    I found out by writing #include and sfter that #include in that order the program works.

    #include
    #include
    using namespace std;

    int main()
    {
    cout<<"Hello world!
    ";
    return0;
    }

    works fine.

    If you have anymore variations please write!!!

  • anthrax11anthrax11 Posts: 511Member
    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.