1
votes
for (int v = 0; v <= WordChosen.length();v++)
{
    if(Letter == WordChosen[v])
    {
        WordChosenDuplicate.replace(v,1,Letter);
    }
}

I get this error

"Error 4 error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::replace(__w64 unsigned int,__w64 unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 3 from 'char' to 'const std::basic_string<_Elem,_Traits,_Ax> &' c:\documents and settings\main\my documents\uni\2nd year\tp2\hangman\hangman\hangman.cpp 147 "

I only got the error after putting this line in

WordChosenDuplicate.replace(v,1,Letter);
4
please show more code - specifically show the definitions of WordChosen, WordChosenDuplicate and Letter.anon
Thanks for the help guysuser91566

4 Answers

3
votes

The std::string::replace() function's parameters are incorrect or you need to invoke a different overload of replace. Something like:

 WordChosenDuplicate.replace(v, // substring begining at index v
                             1, // of length 1
                             1, // replace by 1 copy of
                             Letter); // character Letter
3
votes

Or

WordChosenDuplicate.replace(v,1,std::string(Letter, 1));
1
votes

What do you want to achieve? The version of replace that you are trying to call doesn't exist – as the compiler is telling you. Which of these versions do you mean?

1
votes

It appears that WordChosenDuplicate is a std::string, in which case the 3rd parameter in the replace() method should be another std::string or a c-style const char*. You are trying to pass a single char instead ("Letter"). The error is saying that there is no version of replace() that takes a char as the 3rd parameter.