Error with #include <iostream>

Jan 24, 2013 at 3:04am
I'm having problems with this code -

1
2
3
4
5
6
7
8
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}


I keep getting this error -

1
2
3
4
5
6
7
mingw32-gcc.exe    -c C:\Users\DuckkTV\Desktop\HelloWorld\HelloWorld.c -o C:\Users\DuckkTV\Desktop\HelloWorld\HelloWorld.o
C:\Users\DuckkTV\Desktop\HelloWorld\HelloWorld.c:2:20: iostream: No such file or directory
C:\Users\DuckkTV\Desktop\HelloWorld\HelloWorld.c: In function `main':
C:\Users\DuckkTV\Desktop\HelloWorld\HelloWorld.c:4: error: syntax error before ':' token
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings (0 minutes, 0 seconds)
  


Please help!
Last edited on Jan 24, 2013 at 4:10am
Jan 24, 2013 at 3:05am
1 Error is you just have "return" on line 7. That needs to be "return 0;"
Jan 24, 2013 at 3:07am
That was a copy and paste error :) fixed the "return 0;" on line 7
Still having problems with the #include <iostream>
Jan 24, 2013 at 4:23am
1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include <iostream>

using namespace std;

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


Give that a try. I was having the same error and this fixed it.
Jan 24, 2013 at 4:54pm
if you want to show hello world, you need to use only one 'cout'.
#include<iostream.h>
int main()
{
cout<<"Hello world"<<endl;
return 0;
}
Jan 24, 2013 at 4:57pm
If #include <iostream.h> works you should think about updating your compiler.
@powerbg We weren't talking about he cannot see the results. He cannot compile it. Also use Code tags.

The stdafx thingy shouldn't be your case, as your project is on your desktop, and stdafx is a VS's thing who by default puts your projects in the Documents folder.

Also try renaming your files from .c to .cpp
Last edited on Jan 24, 2013 at 4:58pm
Jan 24, 2013 at 4:58pm
Still no luck :( What do you use to code/ writing program? I am currently using codeblocks. But I don"t know all my ways around it. Right now what i do is
 
File< New< Empty File

Could that the the problem ?
Jan 24, 2013 at 5:14pm
@EssGeEich
How do i rename it to CPP in CodeBlocks ?
Last edited on Jan 24, 2013 at 5:15pm
Jan 24, 2013 at 5:18pm
You should remove the file from the project, rename it manually, and re-add the file to the project.
Jan 24, 2013 at 5:19pm
try right clicking on the file and selecting "rename" from the context menu.
Jan 24, 2013 at 5:20pm
IT WORKED !!!!!!
Thanks man!
Jan 24, 2013 at 5:21pm
@Disch There is no Rename in C::B
@DuckkTV You're Welcome

EDIT: I must be blind, I just noticed there is a Rename File.
Last edited on Jan 24, 2013 at 5:22pm
Jan 24, 2013 at 5:26pm
oh lol
Jan 24, 2013 at 5:26pm
were is the renmame button ?
Jan 24, 2013 at 7:04pm
Jan 24, 2013 at 7:31pm
Okay thanks!
Topic archived. No new replies allowed.