LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-02-2004, 11:52 PM   #1
caesius_01
LQ Newbie
 
Registered: Oct 2003
Posts: 21

Rep: Reputation: 15
GCC:- 'cout' is an undeclared function when #include <iostream> is included?


I'm getting the GCC compiler to work and have just scribbled this code for a test:

#include <iostream>

int main() {
int a;
a = 5;
cout << a;

return 0;
}

But low and behold I recieve the message: "In function 'int main()': 'cout' undeclared (fisrt use this fuction) (Each undeclared......" and so forth.

Why is cout and cin not recognised when "#include <iostream> is present. Maybe I'm doing something wrong...probably am. Help appreciated.
 
Old 04-03-2004, 12:28 AM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
Code:
#include <iostream>

int main() {
int a;
a = 5;
std::cout << a; 

return 0;
}

Last edited by 320mb; 04-03-2004 at 12:29 AM.
 
Old 04-03-2004, 05:49 AM   #3
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
or:
Code:
#include <iostream>

using namespace std;

int main() {
   int a;
   a = 5;
   cout << a; 

   return 0;
}
 
Old 04-04-2004, 10:09 AM   #4
BooKA.
LQ Newbie
 
Registered: Nov 2003
Posts: 9

Rep: Reputation: 0
Quote:
#include <iostream>

using namespace std;

int main() {
int a;
a = 5;
cout << a;

return 0;
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

Defining these at the top give you access to just typing:

cout << "Whatever";

etc.

 
Old 04-04-2004, 10:26 AM   #5
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Or:

#include<iostream.h>

 
Old 04-04-2004, 11:00 AM   #6
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
although for the majority of c++ headers the only difference between the <name> and <name.h> versions is the use of the std namespace there are some significant differences between iostream and iostream.h, you should not use iostream.h
 
  


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
my iostream.h include won't work slinky2004 Programming 5 09-20-2005 12:37 AM
`cout' undeclared in namespace `std' aw_wolfe Programming 1 04-30-2005 09:25 PM
g++ why cant i #include \<iostream\> ??? qwijibow Programming 4 10-03-2003 07:17 AM
gcc with iostream problem rob99 Programming 9 04-16-2003 09:56 PM
#include <iostream> ERROR alexrm1x Programming 9 03-14-2003 10:04 AM

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

All times are GMT -5. The time now is 01:28 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