Author Topic: Can't find iostream  (Read 9643 times)

Offline cyphercat

  • Single posting newcomer
  • *
  • Posts: 2
Can't find iostream
« on: May 27, 2012, 06:10:51 am »
I downloaded the latest code::blocks,
And upon compiling this code:
#include <iostream>

int main()
{
    cout << "hello world";
}

I get this error:
C:\Users\chris\Documents\c++ code\projects\empty test sdl project\Untitled1.c|1|error: iostream: No such file or directory|
C:\Users\chris\Documents\c++ code\projects\empty test sdl project\Untitled1.c||In function 'main':|
C:\Users\chris\Documents\c++ code\projects\empty test sdl project\Untitled1.c|5|error: 'cout' undeclared (first use in this function)|
C:\Users\chris\Documents\c++ code\projects\empty test sdl project\Untitled1.c|5|error: (Each undeclared identifier is reported only once|
C:\Users\chris\Documents\c++ code\projects\empty test sdl project\Untitled1.c|5|error: for each function it appears in.)|
||=== Build finished: 4 errors, 0 warnings ===|

Why can't I use iostream?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Can't find iostream
« Reply #1 on: May 27, 2012, 06:30:04 am »
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Quote
Remember the file extension matters: *.c is compiled as C file, *.cpp is compiled as C++ file.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cyphercat

  • Single posting newcomer
  • *
  • Posts: 2
Re: Can't find iostream
« Reply #2 on: May 27, 2012, 11:51:26 am »
That solved the problem!
I would have never thought to have looked for it in the faq, and appreciate your bringing it to my attention.
Thank you!

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Can't find iostream
« Reply #3 on: May 27, 2012, 01:21:22 pm »
I believe that the issue here is namespaces.  See a good C++ text for a complete explanation.  Your code also works in one of the two versions below which demonstrate two different ways of specifying a namespace:
[...]
gekdahl
This is not a general programming forum/website, so please stop discussing such stuff, because it violates our forum rules.

And what's more, this is completely unrelated to the error of the OP (iostream not found) !
He/she used a c-file ending and C::B treats such a file as C-code and tries to compile it with a C-compiler, which can not work for c++-code.
The namespace stuff might be a copy and paste error.

EDIT:
and for both:
please use code-tags if you post source-code or log outputs, it's much more readable.

Thank you.