c++ compilation error

Asked by ATUL ARUN JOSHI

Hi All,
I have ubuntu 9.04 installed.
I am new to Ubuntu and linux.
I have installed packages for c++ compilation.
But after compiling c++ program, its giving erro as "cout" not declared in the scope.
The file iostream is present in the system and I have also changed the PATH to point to that directory.But problem still exists.
Can anyone please help me ?

Regards,
Atul Joshi

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Steve
Solved:
Last query:
Last reply:
Revision history for this message
Steve (stupendoussteve-deactivatedaccount) said :
#1

ATUL ARUN JOSHI wrote:
> New question #72413 on Ubuntu:
> https://answers.launchpad.net/ubuntu/+question/72413
>
> Hi All,
> I have ubuntu 9.04 installed.
> I am new to Ubuntu and linux.
> I have installed packages for c++ compilation.
> But after compiling c++ program, its giving erro as "cout" not declared in the scope.
> The file iostream is present in the system and I have also changed the PATH to point to that directory.But problem still exists.
> Can anyone please help me ?
>
> Regards,
> Atul Joshi
>

Do you have #include <iostream> in the header? Using namespace std;
within your function(s)?

Revision history for this message
ATUL ARUN JOSHI (atuljo) said :
#2

Thanks Steven for repplying.
I did include "#include <iostream>" but not "Using namespace std;"
I will try gain and will let you know

Revision history for this message
Best Steve (stupendoussteve-deactivatedaccount) said :
#3

ATUL ARUN JOSHI wrote:
> Question #72413 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/72413
>
> Status: Answered => Open
>
> ATUL ARUN JOSHI is still having a problem:
> Thanks Steven for repplying.
> I did include "#include <iostream>" but not "Using namespace std;"
> I will try gain and will let you know
>

Do not use a capital U, that was a mistake on my part with the reply. It
should be something like:

#include <iostream>

int main(){
 using namespace std;

 cout << "Hello world!\n";

 return 0;
}

You could instead use:

 std::cout << "Hello world!\n";

Without a "using namespace" statement and you would get the same result.

Revision history for this message
ATUL ARUN JOSHI (atuljo) said :
#4

Thanks Steven Susbauer, that solved my question.

Revision history for this message
ATUL ARUN JOSHI (atuljo) said :
#5

I tried with "using namespace std" and program ran successfully