C++ C++;恶魔函数iLodImage-程序退出,访问冲突
我的文件路径是这样定义的:C++ C++;恶魔函数iLodImage-程序退出,访问冲突,c++,devil,C++,Devil,我的文件路径是这样定义的: const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg"; 下面是我用来加载图像的函数: bool loadTexImage2D(const string &fileName, GLenum target) { ... // this will load image data to the currently bound image // at first, we m
const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg";
下面是我用来加载图像的函数:
bool loadTexImage2D(const string &fileName, GLenum target) {
...
// this will load image data to the currently bound image
// at first, we must convert fileName, for ascii, this method is fine?
wstring file(fileName.begin(), fileName.end());
if(ilLoadImage(file.c_str()) == IL_FALSE) { //here the program falls
我的代码出了什么问题?调用
ilLoadImage
时为什么程序会失败?我认为,file.c_str()
作为wchar\u t*
类型应该可以很好地工作吗?感谢您的回答:)正如作者所说,您可以在不初始化lib:D的情况下做任何事情
#include <iostream>
#include <IL/il.h>
int main ()
{
std::string filename = "objects/textures/grass.jpg";
ilInit();
if (!ilLoadImage(filename.c_str())) {
std::cout << ilGetError() << std::endl;
return 1;
}
std::cout << ilGetInteger(IL_IMAGE_WIDTH) << std::endl;
std::cout << ilGetInteger(IL_IMAGE_HEIGHT) << std::endl;
return 0;
}
我很好奇。为什么要使用wchar呢?如果使用文件名加载会发生什么?因为const char*与const wchar\u t*不兼容。。。但我已经明白了。。。问题不在这里,我没有使用
ilInit()初始化DevIl库代码>。。。我的错误
g++ -Wall -pedantic --std=c++11 -g -o app main.cpp -lIL