Jump to content

New to C++, quick question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
mike05cp

mike05cp

    Newbie

  • Members
  • Pip
  • 2 posts
I've worked with C for a few months now and am trying to experiment with C++. I wrote a very small and simple C++ program but am having trouble compiling it.

#include <iostream>

int main()
{
cout << "Hello C++\n";
}

That's it. When I compile I use the command: g++ hello.cpp

I've basically copied the source code from a book just to try. The error when compiling is that 'cout' is not declared in the scope. The solution?

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
You need to include the standard files like this.
#include <iostream>
[COLOR="Red"]using namespace std;[/COLOR]

int main()
{
cout << "Hello C++\n";
}
if you don't put that in you will need to right your setecnece like this std::cout << "Hello C++\n" << std::endl;
Hope I helped.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
mike05cp

mike05cp

    Newbie

  • Members
  • Pip
  • 2 posts
Problem solved. Thanks for the input!

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
No prob.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.