Code::Blocks Forums
User forums => Help => Topic started by: cyphercat 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?
-
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
Remember the file extension matters: *.c is compiled as C file, *.cpp is compiled as C++ file.
Tim S.
-
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!
-
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.