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?
New to C++, quick question
Started by mike05cp, Dec 15 2009 07:32 PM
3 replies to this topic
#1
Posted 15 December 2009 - 07:32 PM
|
|
|
#2
Posted 15 December 2009 - 07:45 PM
You need to include the standard files like this.
Hope I helped.:)
#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.
Science is only an educated theory, which we cannot disprove.
#3
Posted 15 December 2009 - 07:51 PM
Problem solved. Thanks for the input!
#4
Posted 15 December 2009 - 07:52 PM
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.
Science is only an educated theory, which we cannot disprove.


Sign In
Create Account

Back to top









