Windows DatabaseebooksStatistical Information

LWE10266 : Howto write a first version of Hello World with a Microsoft visual Studio compiler

Symptom:

You would like to start from the beginning and write your first programm

Cause:

none

Solution:

To write a HelloWorld application with Microsoft Visual Studio you need to generate a new project. This project has to be generated as a Visual C++ Win32 Win32-console application. (do not use precompiled headers if you want to start from the beginning. Otherwise the following little program will not compile because it needs an extra line #include "stdafx.h")

You write the following in the HelloWorld.cpp file in the editor and start the compilation. (F7 starts the compiler, F5 will compile and run your program)



#include <iostream>
#include <ostream>

int main(void)
{
  ::std::cout << "Hello world!" << '\n';
}

Here you use the namespace std without a using statement first.
As an alternative you could write the following, which is exactly the same:


using namespace std;

int main(void)
{
  cout << "Hello world!" << '\n';
}

Here the namespace std will be used so the cout does not have to be prefixed with ::std to use it. I think this is easier to read than the previous example.

When this little program runs, you can take whichever C++ book from the shelf and start programming. Creating a GUI (grafical user interface) application is a bit more complex and not platform independant. (Here Java goes further than C/C++ by defining a standard GUI library wich C/C++ does not have)

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!
Copyright © 2004-2011 Lubby (V3.0.10 Aug 2011)
Sponsored by Keskon.
Statistical information by Google Analytics