close

題目:
類別物件輸出字串

 

程式碼:

#include <iostream>
//using std::cout;
//using std::endl;

using namespace::std;

//有了這行就不用上面兩行

class Cafeshop
{
public:

   // function that displays message to the Nikiblog user
   void displayMessage()
   {
      cout << "Welcome to the Niki's blog!" << endl;

   } // end function displayMessage
}; // end Nikiblog  

// function main begins program execution
int main()

{
   Cafeshop sheratea;
// create a Cafeshop object named sheratea
   sheratea.displayMessage(); // call object's displayMessage function    

   system("PAUSE");
   return 0; // indicate successful termination
} // end main

 

輸出結果:

"Welcome to the Niki's blog!"

 

說明:
創一個classCafeshop,
再創一個名為
sheratea的物件

 

 

arrow
arrow
    文章標籤
    c++
    全站熱搜

    布拉怡 發表在 痞客邦 留言(0) 人氣()