PlayaVole PlayaVole - 3 years ago 152
C++ Question

C++ weird error strstr

check the screenshot, i honestly have no idea what's wrong with it

can anyone help me?

if (strstr(pMaterial->GetTextureGroupName(), "World textures"))
pMaterial->ColorModulate(0.5, 0.5, 0.5);


1: C2665 'strstr': none of the 2 overloads could convert all the argument types

2: E0304 no instance of overloaded function "strstr" matches the argument list

Ron Ron
Answer Source

Your GetTextureGroupName() function is of a std::string type. The std::strstr() function does not accept a std::string as a parameter. Use the string c_str() member function instead:

if (std::strstr(pMaterial->GetTextureGroupName().c_str(), "World textures")){
    pMaterial->ColorModulate(0.5, 0.5, 0.5);

Rather than falling back to C style strings you should explore the std::string facilities as pointed out in the comments. The modified example uses the std::string::find member function:

if (pMaterial->GetTextureGroupName().find("World textures")!= std::string::npos){
    pMaterial->ColorModulate(0.5, 0.5, 0.5);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download