C++ Programming For Beginners

1. 打开Visual C++ 6.0——>新建项目——>选择Win32 Console Application

C++ tutorial: C++ Project

2. Insert——>New Class

C++ tutorial: New Class

C++ tutorial: Class type and name

C++ tutorial: Class View

3. 为Greeting类新建属性和方法

C++ tutorial: Add member variable

C++ tutorial: Variable Type

右击Greeting——>Add Member Function…

C++ tutorial: Add Member Function

4. 点击File View选项卡,可以看见Greeting.cpp  Greeting.h

        在Greeting.h中可以看见刚才添加的属性和方法:

class Greeting 
{
public:
    void PrintMessage();
    Greeting();
    virtual ~Greeting();

private:
    char* message;
};

        双击Greeting.cpp,为message 和PrintMessage方法赋值并引用头文件:

#include <stdio.h>

Greeting::Greeting()

{

        message="Hello World!";

}

void Greeting::PrintMessage()

{

        printf(message);

}

5. 在HelloWorld.cpp中的main函数中调用Greeting类的PrintMessage方法:

#include "Greeint.h"

int main(int argc, char* argv[])

{

Greeting gr;

gr.PrintMessage();

return 0;

}

6. 编译运行

首先 Build——>Build HelloWorld.exe (或F7)

C++ tutorial: Build Executable

然后 Build——>Execute HelloWorld (或Ctrl+F5)

C++ tutorial: Execute Application

 

注:文中红色部分为需要键入的内容或需要进行的操作;蓝色部分为需要操作的文件。

参考资料:http://www.configure-all.com/visualc.php

12/26/2008  by  Chilly

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s