1 // Cplus001.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 #include "iostream" 6 #include "string" 7 8 using namespace std; 9 10 //the definition of class 11 class Person 12 { 13 public: 14 void speak(); 15 private: 16 string words = ""; 17 void getwords(); 18 }; 19 20 21 22 int _tmain(int argc, _TCHAR* argv[]) 23 { 24 string str; 25 cout << "Please Input the Words:" ; 26 cin >> str; 27 cout << "The input is :" << str << endl; 28 Person *p = new Person(); 29 p->speak(); 30 return 0; 31 } 32 33 //the realization of class 34 void Person::getwords() 35 { 36 words = "Welcome to China!"; 37 } 38 void Person::speak() 39 { 40 getwords(); 41 int num = words.length(); 42 cout << "I will say " << num << " letter." << endl; 43 cout << words << endl; 44 }