C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

C++ Tutorial - Lesson One Learning How to Compile With Visual C++ 2005

By David Bolton, About.com

2 of 8

A Breakdown of Example 1, Line By Line.

The first two lines include headers for stadafx.h and iostream. The first one is needed to build applications. Afx is short for Application Framework and this includes the support code needed to turn a .obj file into a fully executable file. (This is only for Microsoft compilers). When you compile C++ files, they are transformed into individual object code files. Each file holds just the object code from the associated .cpp file. Then a linker program runs, which takes all the object files, adds any system files and outputs a fully functioning executable.
using namespace std;
This tells the C++ compiler that it should use identifiers from the std library namespace. Without it, the first line in the main() block would need to be prefixed with std::.
std::cout << "Hello World";
Without the namespace line, every instance of cout would need a std:: or else will not compile.
cout << "Hello World";
The statement cout is the equivalent of printf in C. If you prefer to use printf then add the following line.
#include <stdio.h>
and change the cout to
printf ("Hello World") ;
C++ was designed to be compatible with c which is why printf() still works. You can use either. In a later tutorial, I will show all the formatting possibilities with cout.

On the next page : Another example

Explore C / C++ / C#

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C++
  5. Learn C++ Programming
  6. Learn About Example 1

©2009 About.com, a part of The New York Times Company.

All rights reserved.