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);
-
What do you want to achieve? The version of
replacethat you are trying to call doesn't exist – as the compiler is telling you. Which of these versions do you mean?: Sorry i was following this book and they say "str1.replace(m,n,str2) and Paramenters m and n are of type string::size_type"Konrad Rudolph : Your third argument has to be of type `string`, though (not `char`). -
The
std::string::replace()function's parameters are incorrect or you need to invoke a different overload ofreplace. Something like:WordChosenDuplicate.replace(v, // substring begining at index v 1, // of length 1 1, // replace by 1 copy of Letter); // character Letter -
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.
-
Or
WordChosenDuplicate.replace(v,1,std::string(Letter, 1));
0 comments:
Post a Comment