Code::Blocks/ Dev-c++: error: iostream: No such file or directory
Solution 1
Is this in a file like "program.c" or "program.cpp"? If it's a .c file, then your compiler may be interpreting it as C, and not C++. This could easily cause such an error. It's possible to "force" the compiler to treat either such extension as the other, but by default, .c files are for C, and .cpp files are compiled as C++.
It's either this, or somehow your default "include" directories for the standard library are not set up right, but I don't know how you'd fix that, as that'd be compiler/environment dependent.
Solution 2
I also had that problem when trying to run my first program in Code::Blocks. My file was saved with '.c' extension as 'test.c' and when I saved it as 'test.cpp', it worked fine.
It is also worth mentioning that I had to restart Code::Blocks before new 'test.cpp' file was compiled successfully.
Solution 3
While saving your source code before compiling just save the name with extension ".cpp". You wont get the error..
Solution 4
Use <iostream>
instead of <iostream.h>
and add std::
before cout
, cin
etc
Use std::cout << "Welcome";
instead of cout << "Welcome";
Save the file with .cpp
extension
Solution 5
I got the same problem.
Change #include < iostream.h > to #incude < iostream >
Consequently, in your program, change every keyword related to iostream, such as cin cout and endl to std::cout, std::cin and std::endl
That'll do the trick
sap
Updated on February 07, 2021Comments
-
sap over 3 years
I downloaded Code::Blocks from here: http://www.codeblocks.org/downloads/26
I'm learning c programming. When I run the following program, I get error:
iostream: No such file or directory error: syntax error before "namespace" warning: type defaults to `int' in declaration of `std' warning: data definition has no type or storage class In function `main': error: `cout' undeclared (first use in this function) error: (Each undeclared identifier is reported only once error: for each function it appears in.) error: `cin' undeclared (first use in this function)
I'm running the following program:
#include <iostream> using namespace std; int main() { int x; x = 0; do { // "Hello, world!" is printed at least one time // even though the condition is false cout<<"Hello, world!\n"; } while ( x != 0 ); cin.get(); }
I tried Dev-C++, I get the same error. How to fix this?
-
Mat about 12 yearsNo, don't do that.
iostream.h
is way old.<iostream>
is what you should include for C++ code. -
Nathan Tuggy about 7 yearsThat's already in the question code. With the proper case, even.