#include<iostream>#include<string>
using namespace std;
class Welcome
{
char w[100];
public:
void display()
{
cout<<w<<endl;
}
Welcome(char *s="Welcome")
{
strcpy(w,s);
}
Welcome(const Welcome &t) {
strcpy(w,t.w);
}
~Welcome()
{
cout<<"Goodbye!\n";
}
void set(char *p)
{
if(p)
{
strcpy(w,p);
}
}
char* get()
{
return w;
}
void talk()
{
do {
cout<<"输入:";
cin>>w;
if(strcmp(w,"OK")!=0)
{
cout<<"输出:"<<w<<endl;
}
}while(strcmp(w ,"OK")!=0);
cout<<"All right!"<<endl;
cout<<"Goodbye!"<<endl;
}};
int main()
{
Welcome we;
Welcome you(we);
you.display();
you.set("How are you?");
cout<<you.get()<<endl;
you.talk();
you.display();
return 0;
}
题目要求是直接输入:What's your name?
然后自动输出:What's your name?
输入时不能加双引号的
那么建议采用cin.get(w, 100) 来做
追问出问题啊