`fopen'和qt(mingw)的错误
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
您是否成功?
相关文章:
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 分段 Linux Ubuntu 中的 g++ 错误,但在 Windows 中的 g++/MingW 中,在 C++ 中打
- SFML 库 - 在 MinGW 构建期间未找到错误
- CMAKE Mingw-W64:尝试构建时出现奇怪的错误
- 是 VS 代码 MinGW 与 Win32 中未定义的错误
- CodeBlocks,C++,mingw-w64编译器,Windows 10,错误:对`DAQmxCreateTask&
- dev在试图从dev c++mingw 4.8.1中的文件读取时接收分段错误
- C++线程错误:没有名为"类型"MINGW 的类型
- 使用 MinGW 构建 ASSIMP 会导致文件太大错误
- 使用程序集嵌入数据时"Undefined reference"错误,使用适用于窗口的 mingw-w64 编译(COFF 而不是 ELF)
- 代码::块 (MinGW) #include <priority_queue>上的编译错误
- VS2017 的输出错误,但 mingw 有效
- 尝试在Visual Studio工作时使用CLION的Boost 1.69.0,但给出了奇怪的MINGW错误
- MinGW 错误关于 TITLEBARINFO 未声明
- MINGW错误:“线程”不是“ STD”的成员
- C++好友模板函数-minGW错误,但不是VS2015
- 队列用户APC - 抛出异常崩溃,可能是 mingw 错误
- wxWidgets 编译 MinGW - 错误 1 和错误 2
- C++ Qt MingW 错误的重新定位0xc rdata 部分中的地址
- MinGW 错误:'min'不是 'std' 的成员