Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iostream.h error

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
0
0
GB
hello

i have wrote a basic program

#include <iostream.h>

int main()
{
cout << &quot;hello world\n&quot;;
return 0;
}

when i compile

gcc test.cpp -o test

i get the following error

test.cpp:1: iostream.h: No such file or directory




 
> #include <iostream.h>
This is regarded as being obsolete. New C++ uses include files without any .h

Another significant difference is the idea of namespaces.

Here are some examples.
Code:
#include <iostream>
using namespace std;
int main()
{
 cout << &quot;hello world\n&quot;;
 return 0;
}

Code:
#include <iostream>
using std::cout;
int main()
{
 cout << &quot;hello world\n&quot;;
 return 0;
}

Code:
#include <iostream>
int main()
{
 std::cout << &quot;hello world\n&quot;;
 return 0;
}

Which form you choose depends on your code. For small programs which just use the standard library, you can get away with the first one.

Larger programs which use many libraries (each with their own namespace) should perhaps be written in one of the alternative forms.

--
 
try to use g++

Ion Filipski
1c.bmp
 
Having the same problem. I cut and pasted the examples
and still got the same error:

newhello.c:1:20: iostream: No such file or directory

Thanks in advance
Ron
 
Did you use
[tt]g++ test.cpp[/tt]

gcc is the 'C' compiler, used to compile prog.c files
g++ is the 'C++' compiler, used to compile prog.cpp files

> newhello.c:1:20: iostream: No such file or directory
Because this is now a C program, which you should compile with gcc, and use #include <stdio.h> (not iostream) for standard input/output.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top