• Home
  • Blog
  • Access Violation trying to read file

Access Violation trying to read file

0 comments

Im trying to read a text file but i get an access violation on the [font=”Courier New”]std::getline[/font] line. I replicated the code in a different project and it works there, but not int he original. The code i use is:
[code]
std::vector<std::string> coord;
//Open the file
std::ifstream in(“testCube.txt”);

if( !in.is_open() )
{
   fprintf(stderr, “in not opened!”);
  return -1;
}
if( in.bad() )
{
   fprintf(stderr, “in is bad!”);
   return -1;
}
if( in.fail())
{
   fprintf(stderr, “in failed!”);
   return -1;
}

std::string buf = “”;
while( std::getline(in, buf) )  // HERE IS ACCESS VIOLATION
   coord.push_back(buf);

[/code]

The access violation in full is
[code]
First-chance exception at 0x77518dc9 in Testing_OpenGL.exe: 0xC0000005: Access violation writing location 0x00000014.
Unhandled exception at 0x77518dc9 in Testing_OpenGL.exe: 0xC0000005: Access violation writing location 0x00000014.
The program ‘[4240] Testing_OpenGL.exe: Native’ has exited with code -1073741819 (0xc0000005).
[/code]

The code works. like i said i replicated it in a different project and it works. Im not sure if you guys can help me, maybe someone has seen this before. I’ve been searching for an answer for the past 4 hours. Im about ready to try transering all of me .h’s and .cpp’s to an entirely new project to see if that will work.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}