"Hello world" won't compile in gcc

aneeshm

Deity
Joined
Aug 26, 2001
Messages
6,666
Location
Mountain View, California, USA
I'm currently using gcc on RHEL WS v3(Taroon) , and I can't get it to work compile Hello World" .

The program follows .

#include<iostream>

using namespace std;

int main()
{
cout<<"\nHello World";
}


GCC outputs :

In function int main
undefined reference to cout
Use the function first

or something similar .

Any help ?
 
The compiler said it doesn't know what is "cout".

You can't use C++ stuff just like that with gcc - it's for compiling C, not C++. If you want to stick with C++, use another compiler - e.g. g++.

Or you can simply change the code and use stdio.h and printf instead.

Google groups search for "cout gcc" for more information.
 
#include<stdio.h>

int main()
{
printf("\nHello World!\n");
return 0;
}


// Most Modern compilers will also accept

#include<stdio.h>
void main(){printf("\nHello World!\n");}
 
Back
Top Bottom