I am writing a c++ code (or any sort of code for that matter) after one complete year. And yet I don't think I could have become so bad that I can't make a Hello World program. Still, here I am with so many errors.

Here's the code:-

#include <iostream>

using namespace std;

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

Here are the errors I am getting :-

C:\Documents and Settings\jay mata di\My Documents\c++\hello.c|1|error: iostream.h: No such file or directory|
C:\Documents and Settings\jay mata di\My Documents\c++\hello.c|3|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Documents and Settings\jay mata di\My Documents\c++\hello.c||In function 'main':|
C:\Documents and Settings\jay mata di\My Documents\c++\hello.c|7|error: 'cout' undeclared (first use in this function)|
C:\Documents and Settings\jay mata di\My Documents\c++\hello.c|7|error: (Each undeclared identifier is reported only once|
C:\Documents and Settings\jay mata di\My Documents\c++\hello.c|7|error: for each function it appears in.)|
||=== Build finished: 5 errors, 0 warnings ===|

I guess the problem's with the compiler or my computer (I am using codeblocks.) I ran the program online. It ran just fine. How can I rectify it?

Recommended Answers

All 8 Replies

How are you creating your project?

@firstperson

How am I creating my project? I am sorry but what's that question supposed to mean?

@firstperson

How am I creating my project? I am sorry but what's that question supposed to mean?

You possibly might have created a project with wrong dependencies. When I say create a project, I mean with code blocks. Maybe you have created the wrong type of project. Else you need to manually link the needed headers.

What is your OS?

@firstperson
I don't think I'm running any project. I mean, I opened codeblocks and began working straight away.

@sergent
Its Windows XP SP2

I remember now, I had the same problem. Did you type .cpp at the end of your file name lol?

commented: lol..it worked +3

@sergent

lol..guess what..it worked. Apparently, codeblocks was saving it as a C file by default so thats why there were all these errors. Adding cpp at the end does the trick. Thanks ;)

This forum proved helpful. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.