隨筆-16  評論-9  文章-0  trackbacks-0

          編寫一個創(chuàng)建時,就在屏幕上打印Hello,消失時,就打印Goodbye 的C++程序.

          #include<iostream>
          using?namespace?std;

          class?World{
          ????????
          public:
          ????????????????World(){
          //創(chuàng)建時
          ????????????????????????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 閱讀(2436) 評論(0)  編輯  收藏 所屬分類: cc++

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 育儿| 马鞍山市| 鱼台县| 繁昌县| 永嘉县| 新昌县| 清水县| 奉化市| 乌恰县| 嫩江县| 黎平县| 马公市| 建昌县| 龙口市| 叙永县| 波密县| 镶黄旗| 鹰潭市| 建昌县| 石泉县| 揭阳市| 驻马店市| 宜黄县| 内黄县| 九江市| 宝清县| 星座| 邻水| 内丘县| 岑溪市| 婺源县| 曲松县| 会昌县| 天镇县| 乃东县| 恭城| 昌乐县| 金川县| 精河县| 南平市| 莎车县|