I have a C++ application which needs to read data from a .txt file. I have had this application working for about 8-9 months but after changing another part of the application, it errors out with an "access violation" on any call to getline().
Here is my code:
std::string line;
std::ifstream config;
config.open(fileName);
if(config.is_open()) {
while(config.good())
{
std::getline(config, line);
//Other code to do stuff with the string "line".
}
I have no idea why this is happening now, could it be something to do with some std library dll somewhere or something?
I'm at a complete loss.
As a quick fix is there another easy way to read a file in line by line that would potentially by-pass this problem?
Thanks.
Oh, here is the error message:
0xC0000005: Access violation writing location 0x00000014.
This is not the answer to your question, but a general response.
Don't copy fstream
code from cplusplus.com, your example should be:
std::string line;
std::ifstream config(fileName);
while (std::getline(config, line))
{
//Other code to do stuff with the string "line".
}
Make sure you replace all the debug .libs from linker and replace with them with release versions If you are using Visual C++ for The release Build.
ex: Properties -> Linker -> Input -> Additional Dependencies (replace msvcrtd.lib (last char 'd' for debug lib) from msvcrt.lib (release) )
User contributions licensed under CC BY-SA 3.0