• Register

 

Header files contain predefined functions and other stuff. But including a header file in your program can be an issue which will lead you to the error message on your screen. There will be two sections in this article talking about error “fatal error: iostream: no such file or directory.”

 Cause


Header file causing the error because neither <iostream> or <iostream.h> are standard header files of C. In simple words header file <iostream> is not meant to be for C programming it is defined for the programming language C++, therefore when we are trying to add the header file in the program, the compiler cannot find the file because it is not there.
If you don’t know much about C then you check out its documentation then you will have an idea. Here is the link where you can find such information https://devdocs.io/c/

Solution


Check if you accidentally named the file as file-name.c instead of file-name.cpp
Use the correct compiler which is GCC for C++ programming.

Example
 

#include <iostream>

using namespace std;

int main()
{
      cout << "Hey, you I'm Alive! Oh, and Hello World!\n";
      int x
      cin >> x;
}


Assume that you create this simple program but you named it with .c extension then the compiler will show error because the header file used is for C++ not for C.
 

posted Jul 7 in c++ 100 points