Hello World Problem

Hello, I'm learning via the book Accelerated C.
there's an example that says that I need to write the following code:

#include <iostream>

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


for some reason, it just won't work (compiling results in "1 failed")

So two questions:
1. What am I(or more accuratly, the book) doing wrong?
2. Anybody knows a better book?:)

Thank you!
What compiler are you using? What exactly was the error message it gave you? It looks fine to me. Compiles and runs fine using Code::Blocks. So sounds like your compiler is at issue.
Thank you for the quick reply.

I'm using Microsoft Visual C++ 2010 Express, and there's actually no error (Or i don't know where to check) :S
here's the output I got though:
1>------ Build started: Project: Lawl, Configuration: Debug Win32 ------
1> Lawl.c
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2061: syntax error : identifier 'acosf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2061: syntax error : identifier 'asinf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2061: syntax error : identifier 'atanf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2061: syntax error : identifier 'atan2f'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2061: syntax error : identifier 'ceilf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(21): error C2061: syntax error : identifier 'cosf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(21): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(21): error C2061: syntax error : identifier 'coshf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(21): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(21): error C2061: syntax error : identifier 'expf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(21): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(22): error C2061: syntax error : identifier 'fabsf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(22): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(22): error C2061: syntax error : identifier 'floorf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(22): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(22): error C2061: syntax error : identifier 'fmodf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(22): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(23): error C2061: syntax error : identifier 'frexpf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(23): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(23): error C2061: syntax error : identifier 'ldexpf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(23): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(23): error C2061: syntax error : identifier 'logf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(23): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(24): error C2061: syntax error : identifier 'log10f'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(24): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(24): error C2061: syntax error : identifier 'modff'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(24): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(24): error C2061: syntax error : identifier 'powf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(24): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(25): error C2061: syntax error : identifier 'sinf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(25): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(25): error C2061: syntax error : identifier 'sinhf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(25): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(25): error C2061: syntax error : identifier 'sqrtf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(25): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(26): error C2061: syntax error : identifier 'tanf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(26): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(26): error C2061: syntax error : identifier 'tanhf'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(26): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(28): error C2061: syntax error : identifier 'acosl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(28): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(28): error C2061: syntax error : identifier 'asinl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(28): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(29): error C2061: syntax error : identifier 'atanl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(29): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(29): error C2061: syntax error : identifier 'atan2l'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(29): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(29): error C2061: syntax error : identifier 'ceill'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(29): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(30): error C2061: syntax error : identifier 'cosl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(30): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(30): error C2061: syntax error : identifier 'coshl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(30): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(30): error C2061: syntax error : identifier 'expl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(30): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(31): error C2061: syntax error : identifier 'fabsl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(31): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(31): error C2061: syntax error : identifier 'floorl'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(31): error C2059: syntax error : ';'
1>c:\prograerror C2059: syntax error : ';'

(It keeps going on for a long way).
Try to reinstall, works for me on Code::Blocks
@ApoC

Did you create your file as a 'Console Application', or a "window's" program? The source code you show is for the console.
Did you name the file "Lawl.c"? Many compilers will switch between C and C++ depending on the extension of the file name. ".c" indicates C, ".cpp" indicates C++
so you should make sure the file was saved as "something.cpp" .
Thank you guys again for the quick posts, I appriciate it alot.

Chervil, keen eye there, it worked, thank you very much sir:)
I have another problem -> I didn't want to post another topic to not make any more spam, but if it's against the rules so please tell me and I won't do it again:

After I'm debugging the debugger won't show me what was printed, it just shows up a window and goes out right away, what should I do?

EDIT:
Managed to fix it:), sorry for the double post.
Last edited on
> it just shows up a window and goes out right away, what should I do?

Make the program wait for the user to press enter.

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

int main()
{
    std::cout <<"Hello World!" << /* std::endl; */ << '\n' ;
    std::cin.get() ; // wait till user presses <ENTER>
}
Topic archived. No new replies allowed.