LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GCC:- 'cout' is an undeclared function when #include <iostream> is included? (https://www.linuxquestions.org/questions/programming-9/gcc-cout-is-an-undeclared-function-when-include-iostream-is-included-165594/)

caesius_01 04-02-2004 11:52 PM

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.

320mb 04-03-2004 12:28 AM

Code:

#include <iostream>

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

return 0;
}


Komakino 04-03-2004 05:49 AM

or:
Code:

#include <iostream>

using namespace std;

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

  return 0;
}


BooKA. 04-04-2004 10:09 AM

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.

:)

Mega Man X 04-04-2004 10:26 AM

Or:

#include<iostream.h>

:)

kev82 04-04-2004 11:00 AM

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


All times are GMT -5. The time now is 08:32 AM.