Access Violation trying to read file

Anonymous
timer Asked: Jun 29th, 2013
account_balance_wallet $5

Question Description

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.

This question has not been answered.

Create a free account to get help with this and any other question!

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors