Issues with Hello world

Hi All,
I am VERY new to C++ so please bear with my ignorance/stupidity.
I have a Teach yourself C++ book and the first chapter asks me to create the hello world program.

I have installed Visual studio 2010 and I have started the below:


#include <iostream>

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

This is word for word what the book asks me to do.
However when I try to build this i get the below errors

------ Build started: Project: Hello, Configuration: Debug Win32 ------
Hello.cpp
c:\users\tim-laptop\documents\visual studio 2010\projects\hello\hello\hello.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
Add directive to 'StdAfx.h' or rebuild precompiled header
c:\users\tim-laptop\documents\visual studio 2010\projects\hello\hello\hello.cpp(9): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have tried adding the StdAfx.h to the same file and no go.

If anyone can tell me what i did wrong in this probably simple thing i would be great
this is what your file should look like:

1
2
3
4
5
6
7
8
9
#include "stdafx.h" //above everything it is only need for microsoft visual c++
#include <iostream>

int main()
{
std::cout << "Hello World!" << std::endl;// endl stands for endLine not end1
system("pause");// if you do not add this it immediately closes the program and you see nothing of output
return 0;
}


the green text in the code above are comments and are ignored by the compiler.
Last edited on
So you should have the following headers in this order

#include "StdAfx.h"'
#include <iostream>


Also it seems that you have a typo in the construction

std::cout << "Hello World!" << std::end1;

There shall be letter 'l' instead of digit '1'.
Last edited on
Or you could turn off precompiled headers so you don't have to include stdafx.h.
Absolute Legend Thank you....
Why this is not explained in the book I have no idea.
That was an interesting start!
Why this is not explained in the book I have no idea.


because it is specific to Visual C++.

Maybe it is a good idea to create a empty project without precompiled header... that way you don't need the stdAfx.h file...
Topic archived. No new replies allowed.