I wrote what I thought a quite basic function to read a file. But for a reason I dont know, the std::getline crashes my application, with this output :
The program '[14092] ASREngineApp.exe' has exited with code -1073740777 (0xc0000417)
My code
std::vector<std::string> readFile(const std::string& fileName)
{
//Read file
std::vector<std::string> fileLines;
std::ifstream file;
file.open("toto.txt", std::ios::in);
if (!file)
{
//problem file NULL
//return error
}
else if (!file.is_open())
{
//file not open
//return error
}
else
{
//file opened
std::string str;
while (std::getline(file, str)) //this line crashes
{
fileLines.push_back(str);
}
}
return fileLines;
}
std::copy(std::istreambuf_iterator<char>(file),std::istreambuf_iterator<char>(),std::ostream_iterator<int>(std::cout, " "));file.eof and file.is_open are not crashing, but function like file.tellg and file.seekg are crashing.It looks like the problem is coming from std::ifstream constructor.
See this debug output from my little working application with only the readfile function called from a main:

Then, the following is the debug output from the same function, in my real big application:

So, why in this case, _Mychar is equal to -52'Ì'. This value should be '\0'
User contributions licensed under CC BY-SA 3.0