LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-06-2007, 04:40 AM   #1
azhar_lisec
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Rep: Reputation: 0
Post Problem in C++


hi everybody ,
I am new in C++ in linux.
I just run the sample program in linux. But it shows one error
Can any body tell me the reason and also give solution for my problem.

Error message below:
In function int main():
cout is not declared in this scope

source code :
#include<iostream.h>
int main
{
cout <<"hello world";
return 0;
}


reply to my thread

by
Azharudeen Ahmed.P.A.
 
Old 11-06-2007, 04:56 AM   #2
gjagadish
Member
 
Registered: Oct 2005
Location: India
Distribution: Fedora Core
Posts: 88

Rep: Reputation: 15
u missed parenthesis '()' while defining main function

correct code is

#include<iostream.h>
int main()
{
cout <<"hello world";
return 0;
}
 
Old 11-06-2007, 05:00 AM   #3
azhar_lisec
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Original Poster
Rep: Reputation: 0
reply

I used the parenthesis . but that error has came..



Quote:
Originally Posted by gjagadish View Post
u missed parenthesis '()' while defining main function

correct code is

#include<iostream.h>
int main()
{
cout <<"hello world";
return 0;
}
 
Old 11-06-2007, 05:03 AM   #4
gjagadish
Member
 
Registered: Oct 2005
Location: India
Distribution: Fedora Core
Posts: 88

Rep: Reputation: 15
which compiler did u use to compile ur program?

use c++ or g++
 
Old 11-06-2007, 05:12 AM   #5
azhar_lisec
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Exclamation rply

i used g++ and c++ compiler. I dont know what mistakes made .
Quote:
Originally Posted by gjagadish View Post
which compiler did u use to compile ur program?

use c++ or g++
 
Old 11-06-2007, 05:49 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
cout and friends are defined in the namespace std. Also, the iostream header file does not have the .h on it any more. Prior to standardisation these things were not always the case, so perhaps your sample code was written from guidelines which predate the implementation of the standard.

To use things which are defined in a given namespace, you can either prefix the name of the thing with namespace:: or you can include a use namespace ... statement, which will bring things from that namespace into the global namespace. For example, either of these should work:
Code:
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world" << endl;
    return 0;
}
or:
Code:
#include <iostream>

int main()
{
    std::cout << "Hello world" << std::endl;
    return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration