Chinceapizza
Chinceapizza

Reputation: 1

fatal error: iostream: No such file or directory in Code::Blocks

enter image description here

I get this error when ever I try to run or compile the file.

It's coded in c++ i used Code::Blocks to code it.

Can anyone please help me?

Upvotes: -1

Views: 7435

Answers (3)

sudo apt-get install g++ because the g++ in the release is broken.

Upvotes: -1

Guy Keogh
Guy Keogh

Reputation: 549

Code::Blocks requires all files (including a single .c/.cpp file) to be within a project to compile properly, as it needs a location to store the object (.o) and binary (.exe) files. To do this, click "File" in the top left, "New", "Project". Create the file in this project.

Your code will still not compile as-is, however. Here is how the code is corrected:

  1. iostream is exclusive to C++, so you'll need to create a .cpp file, not a .c file
  2. \n to create a new line must be within the string, e.g. "what's your first number \n". It cannot be outside the string.
  3. A \nwith a backwards slash, rather than a /n is required for a line break.
  4. cin << b\n implies you are trying to divide 'b' with a nonexistant 'n'. The << operator also implies you are trying to pass b to cin, when in fact you are trying to pass the input of cin to b which requires >>. The correct way of writing this is cin >> b;. The line break \n can instead be placed at the end of the previous cout string.

Upvotes: 0

Andrea Grillo
Andrea Grillo

Reputation: 125

Make sure you are using a compiler for C++, like g++. I noticed that the extension of your file is .c and maybe Codeblocks uses a C compiler, like gcc. If codeblock is using gcc the error is normal because C doesn't provide any standard library called "iostream".

Please check the compiler in the project settings and change the extension of the file to .cpp.

Upvotes: 1

Related Questions