fstream包括但是“ifstream not found”和“标识符未定义” [英] fstream included but "ifstream not found" and "identifier is undefined"
问题描述
我不知道该怎么做。我写了一个函数,读取一个.obj文件,与其他几十个其他示例函数,不同的文本文件处理信息。我包括fstream,iostream和sstream。它编译。但是,当我运行它,我得到:
-
在处理一个内存地址(ntdll.dll)抱怨$ b $
-
我的变量监视在ifstream myfile中读取标识符myfile未定义如果我在ifstream myfile(...)行放置一个断点,它读为无法读取内存错误读取字符的字符串也发生在未处理的异常之前。 / p>
-
执行在getline调用期间停在fstream:
virtual void __CLR_OR_THIS_CALL _LOCK()
{//锁定文件而不是流缓冲区
if(_Myfile)
_CSTD _lock_file(_Myfile);
}
相关代码,看起来不怎么样...很简单。文件是一个读取C:\cube.obj的const char *。使用命名空间std。
ifstream myfile文件,ios :: in);
if(myfile.is_open())
{
if(myfile.good())
{
字符串;
while(std :: getline(myfile,line))
{
// Foo
}
}
}
$ b b myfile.close();
我不明白地球上的文件是什么未定义,尽管直接声明它。 fstream显然是正确的包括和可访问。该文件是应该在哪里。
如何进一步调试?教我,哦明智的。在Visual Studio 2013中使用C ++ 11.
解决!我知道这不是指针相关。找到这个职位,尝试它的说法,它的工作完美无瑕现在。 MSVCRTD.lib在我的依赖项中丢失。为什么这没有提到任何地方作为使用fstream prereq是疯了。不能相信包含的是不够的。
我不得不改变运行库设置使用多线程DLL(/ MD),然后添加:msvcrtd .lib到我的依赖项,这解决了我在调试模式下遇到的问题。
http://www.gamedev.net/topic/660218-strange-ifstream-crash/
I don't know what to make of this. I've written a function that reads a .obj file, not unlike the dozens of other example functions out there for processing information from a text file. I've included fstream, iostream, and sstream. It compiles. Yet when I run it I get:
An Unhandled Exception at a memory address (ntdll.dll) that complains about access violation writing location (I'm reading, not writing...).
My variable watch on "ifstream myfile" reads identifier "myfile" is undefined". If I place a break on the "ifstream myfile(...)" line it reads "Unable to read memory" instead. Error reading characters of string also occurs just prior to the Unhandled Exception.
Execution stops here in fstream during the getline call:
virtual void __CLR_OR_THIS_CALL _Lock() { // lock file instead of stream buffer if (_Myfile) _CSTD _lock_file(_Myfile); }
Relevant code, not much to see... pretty straight forward stuff. "file" is a const char* that reads "C:\cube.obj". Using namespace std.
ifstream myfile(file, ios::in);
if (myfile.is_open())
{
if (myfile.good())
{
string line;
while (std::getline(myfile, line))
{
// Foo
}
}
}
myfile.close();
I don't understand how on earth myfile is undefined despite straight up declaring it. fstream is clearly the right include and is accessible. The file is where it should be.
How can I debug this further? Teach me, oh wise ones. Using C++11 with Visual Studio 2013.
SOLVED! I knew it wasn't pointer related. Found this post, tried what it said, and it works flawlessly now. MSVCRTD.lib was missing in my dependencies. Why that's not mentioned anywhere as a prereq for using fstream is crazy. Can't believe the includes aren't enough.
"I had to change the Runtime Library setting to use Multi-threaded DLL (/MD) and then add: msvcrtd.lib to my dependencies, that solved my problems I was encountering for building in debug mode."
http://www.gamedev.net/topic/660218-strange-ifstream-crash/
这篇关于fstream包括但是“ifstream not found”和“标识符未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!