Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;恶魔函数iLodImage-程序退出,访问冲突_C++_Devil - Fatal编程技术网

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