Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't g++ find iostream.h?

Tags:

I'm trying to understand how to compile C++ programs from the command line using g++ and (eventually) Clang on Ubuntu.

I found a webpage which explains MakeFiles and I am following their directions. http://mrbook.org/tutorials/make/

I downloaded the four example files into their own directory.

  • main.cpp
  • hello.cpp
  • factorial.cpp
  • functions.h

I then went ahead and ran their example of how to manually compile without a MakeFile.

g++ main.cpp hello.cpp factorial.cpp -o hello 

When I ran the command from above, I received the following error from g++:

main.cpp:1:22: fatal error: iostream.h: No such file or directory compilation terminated. hello.cpp:1:22: fatal error: iostream.h: No such file or directory compilation terminated. 

My only experience with writing c++ is using an IDE such as VS C++ Express or CodeBlocks. Isn't the compiler supposed to know what iostream.h is and where to find it?

How do I get rid of this error so the program willl compile?

Thanks for any help.

like image 620
quakkels Avatar asked Oct 27 '12 18:10

quakkels


People also ask

Why is iostream not found?

This issue is because of latest changes in iOS12. We have already replaced libstdc++(c++ compiler from GNU) to LLVM C++ 11 Support(libc++) for key "CLANG_CXX_LIBRARY "(C++ standard Library in Xcode Build settings) to fix the issue. Our released beta plugins already have this fix.

What happened to iostream H?

iostream. h is deprecated by those compilers that provide it, iostream is part of the C++ standard. To clarify explicitly there is no mention of iostream. h at all in the current C++ standard (INCITS ISO IEC 14882 2003).

How do I fix iostream H No such file or directory?

h> is not supported, remove it. add this line before main using namespace std; or qualify every functuon call to cout with std:: like std::cout remove getch() it is non-standard function Seems like you are stuck with TurboC++ Add the tag as C++ instead of "help". Keep it simple, remove ".

What can I use instead of iostream H?

If you don't want to use iostreams, your alternatives are C-style stdio and low level OS-specific functions like write() or WriteFile() .


2 Answers

Before the C++ language was standardized by the ISO, the header file was named <iostream.h>, but when the C++98 standard was released, it was renamed to just <iostream> (without the .h). Change the code to use #include <iostream> instead and it should compile.

You'll also need to add a using namespace std; statement to each source file (or prefix each reference to an iostream function/object with a std:: specifier), since namespaces did not exist in the pre-standardized C++. C++98 put the standard library functions and objects inside the std namespace.

like image 107
Adam Rosenfield Avatar answered Sep 23 '22 02:09

Adam Rosenfield


<iostream.h> has never been a standard C++ header, because it did not make it into the C++ standard.

Instead we got <iostream>, in 1998.

Steer well clear of teaching material using non-standard stuff such as <iostream.h> or void main.

However, as a practical solution for your current pre-standard code, you may try to replace

#include <iostream.h> 

with

#include <iostream> using namespace std; 

It’s not guaranteed to work, but chances are that it will work.

like image 41
Cheers and hth. - Alf Avatar answered Sep 24 '22 02:09

Cheers and hth. - Alf