Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code::Blocks/ Dev-c++: error: iostream: No such file or directory

Tags:

c++

dev-c++

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?

like image 432
sap Avatar asked Apr 22 '12 18:04

sap


People also ask

How do I fix Iostream error in code blocks?

you have missing iostream. h file in you mingw directory folder placed inside codeblocks/devc++. what you have to do is just download the file from link given below and replace with your previous mingw folder in codeblocks/devc++.

Does Dev C++ support Iostream?

Dev C++ couldn't support with iostream.


4 Answers

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.

like image 127
Kevin Anderson Avatar answered Oct 18 '22 01:10

Kevin Anderson


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.

like image 43
Olexiy Avatar answered Oct 18 '22 01:10

Olexiy


While saving your source code before compiling just save the name with extension ".cpp". You wont get the error..

like image 2
jibranejaz Avatar answered Oct 18 '22 01:10

jibranejaz


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

like image 1
Aseem Ahir Avatar answered Oct 18 '22 00:10

Aseem Ahir