2017-07-25 488 views
-7

檢查截圖,我真的不知道它有什麼問題C++奇怪的錯誤strstr

任何人都可以幫助我嗎?

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

screenshot

1:C2665 '的strstr':沒有2個重載可以轉換所有的參數類型

2:E0304沒有重載函數 「的strstr」 的實例參數列表匹配

+3

什麼錯誤的屏幕截圖是,它是一個屏幕截圖。請在問題中包含代碼和錯誤(不包括圖片,請勿鏈接圖片) – user463035818

+0

好的,對不起。 – PlayaVole

+3

錯誤告訴你到底發生了什麼問題。你正在傳遞'std :: string,const char [15]',並且沒有接受這些參數的'strstr'的​​重載版本。 –

回答

1

GetTextureGroupName()功能是std::string類型。 std::strstr()函數不接受std::string作爲參數。使用String c_str()成員函數:

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

而不是回落到C風格的字符串,你應該探索在評論中指出的std::string設施。修改後的示例使用std::string::find成員函數:

if (pMaterial->GetTextureGroupName().find("World textures")!= std::string::npos){ 
    pMaterial->ColorModulate(0.5, 0.5, 0.5); 
} 
+2

爲什麼降級到C字符串而不是使用'std :: string'提供的? –

-1

strstr接受兩個char *指針。你可以將其更改爲:

strstr(pMaterial->GetTextureGroupName().c_str(), "World textures") 
+1

我認爲有一個錯字:c_ptr - > c_str –