#include <iostream>
#include <string.h>
using namespace std;
class testwork
{
public:
testwork(string s)//constructor
{
p_s = s;
}
void Print_String()
{
cout<<"Constructor: "<<p_s<<endl;
}
private:
string p_s;
};
int main()
{
string s;
cout<<"Enter a sentence: ";
getline(cin,s);
//在main當中,資料初值、輸入、建立要和object分開,儲存和執行不要混在一起;如此一來才方便用相同資料做不同object
testwork obj01(s);//constructor
obj01.Print_String();
return 0;
}
全站熱搜
留言列表