随笔-16  评论-9  文章-0  trackbacks-0

编写一个创建时,就在屏幕上打印Hello,消失时,就打印Goodbye 的C++程序.

#include<iostream>
using namespace std;

class World{
        
public:
                World(){
//创建时
                        std::cout<<"Hello!\n";
                }
                
~World(){//消失时
                        std::cout<<"Goodbye!\n";
                }
};

//World theWorld;

int main(){
        //cout
<<"Hello World\n";
        World theWorld;
        
return 0;
}

[root@portal ctest]# vi hello.c
[root@portal ctest]# g
++ hello.c -o hello
[root@portal ctest]# .
/hello
Hello
!
Goodbye
!
[root@portal ctest]#

posted on 2007-09-24 15:05 forker 阅读(2403) 评论(0)  编辑  收藏 所属分类: cc++

只有注册用户登录后才能发表评论。


网站导航: