Red Hat Bugzilla – Bug 77483
Cannot compile Hello app with c++ using cout
Last modified: 2007-04-18 12:48:12 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR
Description of problem:
cannot compile simple hello world app in c++ using gcc and the 3.2 iostream
Version-Release number of selected component (if applicable):
Steps to Reproduce:
cout <<"hello world");
3. Save as test.c
4. gcc test.c
Actual Results: Return= test.c:1:21: iostream No such file or directory
test.c: In function 'main':
test.c:4: 'cout' undeclared (first us in this function)
Expected Results: My thought is that the code should compile and that
somewhere the headers are confused.
I have explored with gcc -B and cpp -I etc. to try and get the headers to
respond correctly we can get the app to compile using C++ and mapping to the
backwards directory and using <iostream.h> but that is not the desired method
and comes with an error etc.
This is a C++ program, right? So it should use .C/.cxx/.cpp/.c++ extension, not .c.
Also, if you are using STL in it, you should use g++ compiler driver, not gcc,
so that libstdc++ gets linked in.
And last, cout is in std namespace, so you need to write std::cout
or add using namespace std; or using std::cout; above main.