Skip to main content

Hello World

One of the best ways to learn how to program in a new language is by looking at lots and lots of example programs. The best thing to do is to copy and paste each program below into a text file and compile it. Then, try the experiments. By extending these example programs, you will gain familiarity with different aspects fo C++, and you will feel more confident when it comes time to write programs from scratch.

// hello.cpp: Maggie Johnson
// Description: a program that prints the immortal saying "hello world"

#include <iostream>
using namespace std;

int main() {
 cout << "Hello World!" << endl;
 return 0;
}
Some experiments to try:
  • The most important thing is to make sure you can compile and run this program.

Comments

Popular posts from this blog

Adding Existing Files to a Project

If a file had already been created and exists on a separate folder, drive, directory or project, you can import it and add it to your application. When you decide to add an existing file to a project, because Microsoft Visual Studio allows you a great level of flexibility on the types of files you can add, it is your responsibility to check that the file is valid. If you copy a file from somewhere and paste it in the folder that contains your project, the file is still not considered as part of the project. You must explicitly add it. Before adding an existing file to your project: On the main menu, you can click File -> Add Existing Itemテδ「テ「窶堋ャテつヲ On the main menu, you can also click Project -> Add Existing Itemテδ「テ「窶堋ャテつヲ In the Solution Explorer, you can right-click the name of the project, position your mouse on Add and click Add Existing Itemテδ「テ「窶堋ャテつヲ Any of these actions would open the Add Existing Item dialog box. This requires you to locate the item and select it. O...

Introduction to Microsoft Visual C++/MFC

Microsoft Visual C++ is a programming environment used to create applications for the Microsoft Windows family of operating systems. To use these lessons, you must have installed either Microsoft Visual Studio 2010. Although Microsoft Visual Studio 2010 Professional provides many programming environments for the price of one, in our lessons, we will use it but we will cover only the Microsoft Foundation Class (MFC) library side. After installing it, to use the programming environment, you must first open it. To do that, you would click Start -> (All) Programs -> Microsoft Visual Studio 2010 -> Microsoft Visual Studio 2010. In our lessons, unless used in code, the -> arrow means an action that should follow another. Based on this: Edit -> Copy means click Edit, then click Copy View -> Toolbars -> Custom means click View position the mouse on Toolbars, and then click Custom To start Microsoft Visual C++ or Visual Studio, on the Taskbar, click Start (All) Prog...

Converting a Resource Identifier

An identifier is a constant integer whose name usually starts with ID. Although in Win32 programming you usually can use the name of a resource as a string, in MFC applications, resources are usually referred to by their identifier. To make an identifier name (considered a string) recognizable to an MFC (or Win32) function, you use a macro called MAKEINTRESOURCE . Its syntax is: LPTSTR MAKEINTRESOURCE(WORD IDentifier); This macro takes the identifier of the resource and returns a string that is given to the function that called it. In the strict sense, after creating the resource file, it must be compiled to create a new file that has the extension .res. Fortunately, Microsoft Visual C++ automatically compiles the file and links it to the application.