【发布时间】:2021-12-12 10:08:38
【问题描述】:
我正在尝试通过开发一个基本系统来制作一个基本的选择你自己的冒险风格的游戏,程序通过该系统接受用户字符输入并使用 if-else 语句以特定模式附加字符串来做出决定。在下面的程序中,我尝试在一组条件后使用 strcat 来产生不同的输出,但是我的输出一直失败得很惨。有人能提供的任何帮助都会令人难以置信。
#include <iostream>
#include<cstring>
#include<string>
#include<iomanip>
#include<ios>
#include<limits>
using namespace std;
int main()
{
char str1[50]= "F*ck";
char str2[50]= "You";
char str3[50]= "Me";
char answer[50];
cout<< "Do you like rock music yes or no?";
cin>> answer;
if (answer== "no"){
cout<< strcat(str1,str2);
} else (answer== "yes");{
cout<< strcat(str1,str3);
}
return 0;
}
【问题讨论】:
标签: c++ string if-statement strcat cmath