user1935067
user1935067

Reputation:

no matching function for call to 'std::basic_string<char>::basic_string c++

Hey I'm making a "Make your own adventure game!" Now other then having to run through the hole game I wanted to make a cheat code system and now I'm trying to declare a string witch is equal to over 6 words I don't see what the problem is I did it with only two words and got no errors how ever when I did the same thing with more then 2 words and I got the error.

Main.cpp|27|error: no matching function for call to 'std::basic_string::basic_string(const char [4], const char [6], const char [5], const char [5], const char [6], const char [6])'|

Here's my code:

#include <iostream>
//LVL1
#include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dog.h"
#include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\Dream.h"
#include "C:\Users\QuestionMark\Desktop\Make Your Own Adventure\LVL1\GTFO.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 now\n";
        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 Code\n";
   }

}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 number\n";
    int x;
    cin >> x;
    if(x == 0){
         Dog();
    }else if(x == 1){
         GTFO();
    }else{
         Dream();
    }
}

Upvotes: 0

Views: 16332

Answers (1)

Gibby
Gibby

Reputation: 458

Your problem here is in your declaration of string z, your code is :

std::string z("Dog","Dream","GTFO","Path","Sword","Weird");

your compiler can not find a constructor for std::string that takes 6 arguments try instead

std::string z("any string");

or because you are about to initialize z just

std::string z;

Upvotes: 1

Related Questions