嘿,我正在制作一个"制作你自己的冒险游戏!"现在,除了必须在洞里玩游戏之外,我想制作一个作弊代码系统,现在我正试图宣布一个字符串女巫等于6个以上的单词。我不明白问题是什么。我只用了两个单词就完成了,没有错误。然而,当我用超过2个单词做了同样的事情,却出现了错误。
Main.cpp|27|错误:调用"std::basic_string::basic_string(const char[4],const char[6],const char[5],const char[5],constr char[6],const char[6])"|时没有匹配的函数
这是我的代码:
#include <iostream>
//LVL1
#include "C:UsersQuestionMarkDesktopMake Your Own AdventureLVL1Dog.h"
#include "C:UsersQuestionMarkDesktopMake Your Own AdventureLVL1Dream.h"
#include "C:UsersQuestionMarkDesktopMake Your Own AdventureLVL1GTFO.h"
using namespace std;
int Return();
int Continue();
int main(){
cout << "Welcome to my 'MAKE YOUR OWN ADVENTURE GAME!!!'n";
cout << "Have Fun and enjoy the ride!n";
cout << "Would you like to put in a cheat code??n";
cout << "Yes or No, Cap Sensitive!n";
Return();
return 0;
}
int Return(){
std::string y("Yes","No");
cin >> y;
if(y.compare("Yes")){
cout << "Please Enter Cheat Code nown";
std::string z("Dog","Dream","GTFO","Path","Sword","Weird");
cin >> z;
if(z.compare("Dog")){
Dog();
}else if(z.compare("Dream")){
Dream();
}else if(z.compare("GTFO")){
GTFO();
}else if(z.compare("Path")){
Path();
}else if(z.compare("Sword")){
Sword();
}else if(z.compare("Weird")){
Weird();
}else{
cout << "Invalid Cheat Coden";
}
}else if(y.compare("No")){
return Continue();
}else{
cout << "Invalid Answer!n";
Continue();
}
}
int Continue(){
cout << endl;
cout << "You wake up and your house is on fire what do you do ??n";
cout << "Quick Grab The Dog = 0, GTFO = 1, Go back to sleep = any other numbern";
int x;
cin >> x;
if(x == 0){
Dog();
}else if(x == 1){
GTFO();
}else{
Dream();
}
}
您的问题在于字符串z的声明,您的代码是:
std::string z("Dog","Dream","GTFO","Path","Sword","Weird");
编译器找不到需要6个参数的std::string的构造函数,请尝试
std::string z("any string");
或者因为你即将初始化z只是
std::string z;