Question

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

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?

Enquirer: sap

||

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.

Respondent: Kevin Anderson

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.

Respondent: Olexiy

Solution #3:

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

Respondent: jibranejaz

Solution #4:

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

Respondent: Aseem Ahir

Solution #5:

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

Respondent: Javed Iqbal

Solution #6:

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++.

http://www.4shared.com/rar/owp-D0Km/mingw.html

Respondent: Meghraj Sharma

Solution #7:

I found the problem was cause by having a previous version of cgg and cpp in a Perl installation. The Perl structure did not have the correct library files. When I added C:MinGWbin and C:MinGWMSYS1.0bin to the path, I added them at the end so it picked up the Perl install first. I moved the path variable entries to the beginning and reopened my cmd window and it now works because it finds the MinGW version first.

Type path to see your path environment varialble. Mine now looks like:

C:MinGW>path
PATH=C:MinGWbin;C:MinGWMSYS1.0bin;C:Perlsitebin;C:Perlbin;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program FilesWIDCOMMBluetoothSoftware;
Respondent: Hughie

Solution #8:

Apparently you want to create a c++ file. But you allowed your computer to auto provide the file extension C/C++. When it does that it automatically provides a file extension of “.c”. Which is not corect. You want “.cpp”.

Solution: Rename your file with a “.cpp” extension, or else explicitly state your extension when saving new files by putting “.cpp” (without quotes of course) after your intended file name; i.e. specify your file extension.

Respondent: Ken Cole

Solution #9:

I tried in Dev-C++ . Instead of iostream.h use iostream also write the using namespace std;

#include<iostream>
using namespace std;
int main()
 {
   cout<<"Hello Worldn";
   return 0;
 }
Respondent: I.T.S Channel

Solution #10:

you written your program in C++ code use c code then your program run correctly

in first line use it

#include <Io stream.h>
main ()
{

in ending line use it

system (pause");
Respondent: user3023906

Solution #11:

You are trying to make a C game right? If you are your code is C++ not C. So if you are trying to make a C game than you should change your code. This might help.

Respondent: zane

Solution #12:

Just put “Using namespace std;” before main() to define the scope of identifiers you are using. This will handle your problem easily.

Respondent: Varun

Solution #13:

Try including iostream.h instead of iostream.

Respondent: IwishIknewMore

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy