題目:
類別物件輸出字串
程式碼:
#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!"
說明:
創一個class為Cafeshop,
再創一個名為sheratea的物件