[英]Error with `fopen` and QT(MinGW)
我的QT應用程序中包含以下代碼:
FILE * file = fopen(m_fileName.c_str(), "rb");
,其中m_fileName
的類型為std::string
。 此代碼在Visual Studio2012中可以正常工作。 但是在QT 4.7.4(MinGW編譯器)中,我的程序在這一行崩潰了。
我真的不知道這段代碼有什么問題。 我沒用過MinGW,所以肯定有些我不了解的東西。
更新:
來自main.cpp
代碼:
std::string fileName = "test1.bmp";
m_pTexture1 = new Texture(GL_TEXTURE_2D, fileName);
if (!m_pTexture1->Load()) {
return;
}
Texture.cpp
簡化代碼:
Texture::Texture(GLenum TextureTarget, std::string FileName)
{
m_textureTarget = TextureTarget;
m_fileName = FileName;
}
bool Texture::Load()
{
try {
FILE * file = fopen(m_fileName.c_str(),"rb");
}
catch (...) {
std::cout « "Error loading texture '" « m_fileName;
return false;
}
}
Texture.h
代碼:
class Texture
{
public:
Texture(GLenum TextureTarget, std::string FileName);
bool Load();
private:
std::string m_fileName;
GLenum m_textureTarget;
GLuint m_textureObj;
unsigned int width, height;
unsigned char * data;
};
是的,@ PaulMcKenzie是正確的。 我試圖在構造函數中打印m_fileName
,它粉碎了程序。 看起來m_fileName
無法初始化。 但是,我不知道為什么會這樣。
更新2
我發現它由於printf
和其他C I / O功能而崩潰。 很奇怪。
您的代碼是語法錯誤。 (托架)
FILE * file = fopen(m_fileName.c_str()), "rb"); ^ this one
你編譯成功了嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.