I have this code:
std::string ff = "C:\\res\\pp.txt";
std::ifstream test(ff);
if(test.is_open())
{
std::string s;
std::getline(test, s);
}
If I put a breakpoint at the construction and analize the test object, it is constructed but the buffer is an incorrect pointer. Then, getline crashes because test is corrupted.
As a side information, this code is executed into a project that links with some libraries as gameplay3d.
Some ideas?
EDIT: This is the stack trace:
msvcp100d.dll!std::_Xfiopen(const char * filename, int mode, int prot) Línea 85 C++ msvcp100d.dll!std::_Fiopen(const char * filename, int mode, int prot) Línea 94 + 0x11 Bytes C++ sample-browser.exe!std::basic_filebuf >::open(const char * _Filename, int _Mode, int _Prot) Línea 220 + 0x1d Bytes C++ sample-browser.exe!std::basic_ifstream >::basic_ifstream >(const std::basic_string,std::allocator > & _Str, int _Mode, int _Prot) Línea 725 + 0x1f Bytes C++ sample-browser.exe!Audio3DSample::initialize() Línea 30 + 0x15 Bytes C++
All seems to be ok until code hits _Xfiopen. At this moment, fp is not created and, although ifstream is created, the internal filebuffer is null. If I put this code in another project it works, and more importantly, the code that constructor calls and the stack is totally different.
is_openrather than justif (test)aside), and it is obviously testable as valid when isolated in a stand-alonemain()program. Which means your problem is somewhere else. - WhozCraigif(test.is_open() and test.good())- Nikos C.