c+写一个qq机器人
#include
// 定义QQ机器人类 class QQRobot { private: string name; // 机器人名称
public: QQRobot(string n) { name = n; }
void sayHello() {
cout << "你好!我是" << name << ",有什么可以帮助你的吗?" << endl;
}
void chat() {
string question;
cout << "请输入你的问题(输入\"q\"退出):" << endl;
while (true) {
getline(cin, question);
if (question == "q") {
break;
}
cout << "你的问题是:" << question << endl;
cout << "这个问题太难了,我还不会回答呢!" << endl;
cout << "请输入你的问题(输入\"q\"退出):" << endl;
}
}
};
int main() { QQRobot robot("小Q"); robot.sayHello(); robot.chat();
return 0;
原文地址: http://www.cveoy.top/t/topic/hSBS 著作权归作者所有。请勿转载和采集!