LinuxQuestions.org
Visit Jeremy's Blog.
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-18-2002, 09:45 AM   #1
bigpimpin79
LQ Newbie
 
Registered: Nov 2002
Posts: 2

Rep: Reputation: 0
g++ compiler help


hello
i am a first time linux user and had just installed RH Linux 8 on my PC. i seem to have a problem using the g++ compiler.

my code is:

#include<iostream>
int main(){
cout<<"Hello World";
return 0;
}

the compiler error that i get is:

Hello.cc:3:'cout' undeclared(first use this function)
Hello.cc:3:each undeclared identifier is reported only once for each function it appears in.)

help, anyone?
thanks!
 
Old 11-18-2002, 09:50 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you are not using cout in teh correct namespace. either say:
Code:
using namespace std;
or
Code:
std::cout<<"Hello World";
that'll compile it, but it still won't work, as you're not flushing the output stream, you'll want something like:
Code:
cout<<"Hello World" << endl;
instead
 
Old 11-18-2002, 05:42 PM   #3
bigpimpin79
LQ Newbie
 
Registered: Nov 2002
Posts: 2

Original Poster
Rep: Reputation: 0
thanks!

how come you have add that extra piece of code just to make iostream work? i have been writing and compiling in RH Linux 7.3 and the '#include<iostream>' alone worked fine.

thanks again
 
Old 11-18-2002, 05:45 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i don't know, if it was working before, it was wrong somewhere alogn the line.
 
Old 11-18-2002, 07:23 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by bigpimpin79
thanks!

how come you have add that extra piece of code just to make iostream work? i have been writing and compiling in RH Linux 7.3 and the '#include<iostream>' alone worked fine.

thanks again
That's because the standard that requires
'std::' or the usage of 'using namespace std;'
(which, btw, isn't encouraged) is only about
4 years old :} and some compiler-builders
are slow to respond ;)
Cheers,
Tink
 
  


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
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
C++ IDE+Compiler?Java IDE+compiler? Boby Linux - Software 3 05-31-2005 01:12 PM
Compiler conundrum: Which came first, a compiler, or it's source code? fr0zen Programming 21 01-29-2004 04:31 AM
No compiler to compiler the compliler NewtonIX Linux - Newbie 13 11-03-2003 05:32 AM
compile a compiler without a compiler? lackluster Linux - General 18 01-02-2003 07:55 PM

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

All times are GMT -5. The time now is 06:47 PM.

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