使用我有一個字符串數組C++的std :: string到char與OpenGL的LoadBMP
string name[1000];
與
int counter;
counter = 0;
while(FindNextFile(fHandle, &wf))
{
... //some more code which is checking if its a folder
string theName = wf.cFileName;
if(theName.find(".bmp") != std::string::npos)
{
name[counter] = theName;
counter++;
}
}
我加入每個.bmp文件到我的名字排列。
使用NeHe's Tutorial我將紋理添加到我的Qubes中,工作得很好。
現在我定製的代碼如下所示:
int n; string imageFileString[1000]; char *imageFile[1000];
for(n=0; n<1000; n++)
{
imageFileString[n] = name[n];
imageFile[n] = new char[imageFileString[n].length()];
strcpy(imageFile[n], imageFileString[n].c_str());
if(TextureImage[n] = loadBMP(imageFile[n]))
{
... // Some more Functions to set textures
}
}
一切運作良好,只是我的BMP文件的arent加載。
如果我設置int n; string imageFileString...
,所以對於for(...)
循環是在不改變任何東西裝我的照片前添加
name[0] = "pic1.bmp";
name[1] = "pic2.bmp";
name[2] = "pic2.bmp";
name[3] = "pic2.bmp";
。我的第一個觀點是,這個名字數組有沒有entrys,但我創建了一個日誌文件與輸出
name[0] << endl << name[1] << endl << name[2] ...
,並在我的日誌文件是相同的名稱
pic1.bmp
pic2.bmp
pic3.bmp
所以我認爲有一些其他錯誤將cFileName添加到我的數組中。
任何人都可以幫助我嗎?我不知道如何解決這個問題,我的意思是我不知道什麼是錯的...
而不是字符串名稱[1000]你爲什麼不使用std :: vector的名;.並使用names.push_back(theName);. –
yasouser
2011-01-07 21:30:04