C++ compiler problems

I've just installed Visual studio.net. I'm a new C++ programmer and though i'd just test things out with a standard 'hello world':-

#include

main()

{
cout "hello world";
}

Thing is the compiler errors with 'cout undeclared identifier'

Anyone know the solution please!

Comments

  • : I've just installed Visual studio.net. I'm a new C++ programmer and though i'd just test things out with a standard 'hello world':-
    :
    : #include
    :
    : main()
    :
    : {
    : cout "hello world";
    : }
    :
    : Thing is the compiler errors with 'cout undeclared identifier'
    :
    : Anyone know the solution please!
    :




    #include

    main()

    {
    cout << "hello world";
    }

  • jasonjason United Kingdom
    : I've just installed Visual studio.net. I'm a new C++ programmer and though i'd just test things out with a standard 'hello world':-
    :
    : #include
    :
    : main()
    :
    : {
    : cout "hello world";
    : }
    :
    : Thing is the compiler errors with 'cout undeclared identifier'
    :
    : Anyone know the solution please!
    :
    [code]
    #include "stdafx.h"

    #using

    using namespace System;
    [red]using namespace std;[/red]

    int _tmain()
    {
    cout << "hello";
    }[/code]

    [red]Regards, Jason[/red]

  • : I've just installed Visual studio.net. I'm a new C++ programmer and though i'd just test things out with a standard 'hello world':-
    :
    : #include
    :
    : main()
    :
    : {
    : cout "hello world";
    : }
    :
    : Thing is the compiler errors with 'cout undeclared identifier'
    :
    : Anyone know the solution please!
    :
    I know that this is a late contribution to this thread but I wanted to put in my two bits worth for new programmers when they have similar problems.

    1) You need to use the 'insertion operator' '<<' to put the double quoted text string into cout which is an instance of an output stream.

    2) It is not good practice to refer to .h files in modern C++.

    3) It is best to not do the 'using namespace std;' thing under the '#include' line as, in large projects, there might be name clashes between the various project name spaces.

    If one wants to create the minimum file (with the exception of the '<< endl' for a <CR> at the end of the line) then in VS create a new C++ console project and make it an empty project. Then enter the following:

    #include

    void main() {
    std::cout << "hello world" << std::endl;
    }

    Try to not use namespaces globally. That said, this also works:

    #include <iostream>
    using namespace std;

    void main() {
    cout << "hello world" << endl;
    }

    This does make the code more readable. Just keep in mind that you have cluttered up you global environment.
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!

Categories