Hey guys,
Currently I'm going to school for a minor in comp sci. I've got a C++ class coming up and my family got me Sams Teach yourself C++. I'm stuck on the very first lesson. Its a simple Hello world app.
This one wont work it hangs on the std::cout, then i pull this one from a website to test it and this one works.
#include <iostream>
using namespace std;
void main()
{
std::cout << "Hello World!" << endl; std::cout << "Welcome to C++ Programming" << endl; }
Can someone please explain to me why? The book has me using MSV C++ 2010 Express. Thanks
The example you got from the website doesn't actually conform to the C++ standard, as main needs to return int. And "using namespace std;" is also generally looked down upon.
some programs will let it compile but main is expected to return 0;
when the program completes.
It could return something else if a exception is encountered.
also another thing I see in the first code is that you are missing a extra : in std::endl;.
The first way you wrote it was actually the better way to use namespaces then the usingnamespace std;, but that is for later, when beginning learning C++ you can use usingnamespace std; with no problem just try not get into the habbit of doing it because it loads a hold bunch of crap you don't need.