![](/img/trans.png)
[英]No suitable conversion function from “std::string” to “const char *” exists
[英]No suitable conversion function from std string to const char * exists
我正在使用一個預建的庫,為了讓我加載紋理並顯示它,我必須使用此代碼。 我希望加載多個文件並將它們作為struct
存儲在數組中,以便可以調用和顯示它們。 我不斷收到此錯誤:
不存在從
std
字符串到const char *的合適轉換函數
嘗試在以下部分加載時。
for (int i=0; i<CUTSCENE; i++)
{
stringstream s;
int fileNum = i+1;
string FirstPart = "Textures/GameVideos/Game (";
string LastPart = ").png";
s << FirstPart << fileNum << LastPart << endl;
string fullfileName;
s >> fullfileName;
cutSceneMain[i]->texture = new Texture2D();
cutSceneMain[i]->texture->Load(fullfileName, false);
cutSceneMain[i]->sourceRect = new Rect(0.0f, 0.0f, 700, 700);
cutSceneMain[i]->position = new Vector2(0.0f, 0.0f());
}
問題很可能與您調用Load
的方式有關,一種解決方法是使用fullfileName.c_str()
:
cutSceneMain[i]->texture->Load(fullfileName.c_str(), false);
^^^^^^^
Load
需要const char*
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.