Compiler doesn't work

So, im using codeblocks to write C++ and i have MinGW, but for some reason, it wont compile the first program in the tutorial... any one know whats wrong with it and how i can fix it? Thanks for your time.

i dont think its the compiler, here is the build errors i get:

C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c|1|error: iostream: No such file or directory|
C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c|2|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c||In function 'main':|
C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c|6|error: 'cout' undeclared (first use in this function)|
C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c|6|error: (Each undeclared identifier is reported only once|
C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c|6|error: for each function it appears in.)|
||=== Build finished: 5 errors, 0 warnings ===|

so.... yeah... and heres is what i "ran"

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main ()
{
    cout<< "Hello World!!";
    return 0;
}


it's supposed to be "hello world!" program to introduce me to C++, but it's not working for some reason.
Last edited on
Your code seems fine... Must be how you set up MingGW with CodeBlocks. Try a reinstall or compile it with g++ in the command line
Have you created a "Console Application" project or did you start an "Empty project"?
Does it show any error message?
If it is not try this..
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main ()
{
    cout<< "Hello World!!";
    system("pause");
    return 0;
}
AMCerasoli:
I think i made it from empty.

Chathu:
why dont you read my first post, I dont know why you are asking this... AT ALL.
I figured it out. it seems you have to have an empty line in line 2.

1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main ()
{
    cout << "Hello World!";
    return 0;
}
Unless you're running a *really* odd (and non-compliant) version of a C++ compiler, that empty line means nothing; your solution was somewhere else.
Wow. No one spotted this?
Shutdown Commander.c

That's a C source extension. It should be .cpp (or .cxx or .C or any other I'm forgetting).
what helios i didn't get that? plz explain :)

ok so i wishiknew ...yeah i saw ur first post.
I figured it out. it seems you have to have an empty line in line 2

that is not c++. You don't need any space in between those lines.
Last edited on
@helios a *.c file should work fine... at least with g++ it works
Except it's using namespaces and commands that don't work in C. Won't the file extension spoof the compiler?
@helios a *.c file should work fine... at least with g++ it works
True. Except that OP is not using g++ directly. He's using an IDE that decides which compiler to call based on the file extension.
...and in any case, the OP should be using standard file extensions. Use ".c" for C code only. Use ".cpp" or ".cxx" or ".cc" (etc) for C++ code.
uhhh..... i just did what the tutorial said... lmao. I didnt, however check the file extension, so i will do so tomorrow because it's around 10:30pm for me, thanks for the rapid response! Yall have been REALLY helpful to me.
Yhea for that reason I ask you if you started an empty project, because when you create a new file it make it usint the .c extension instead of .cpp and the standar library iostream is a c++ library, so code::blocks is searching iostream in the wrong place.

For that reason you got:

C:\Users\Jonathan\Desktop\C++\Shutdown Commander\Shutdown Commander\Shutdown Commander.c|1|error: iostream: No such file or directory|
.cpp extension = works perfectly! God this is so much better the ms visual! Easy peasy! Thanks you guys!
Topic archived. No new replies allowed.