Access Violation trying to read file

User Generated

anab511

Programming

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.

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Causes

Usually, there is no obvious cause of a hernia. Sometimes hernias occur with heavy lifting, straining while using the toilet, or any activity that raises the pressure inside the belly area. Hernias may be present at birth, but the bulge may not be noticeable until later in life. Some patients may have a family history of hernias.

Babies and children can get hernias. It happens when there is weakness in the belly wall. About 5 out of 100 children have inguinal hernias. They are more common in boys. Some children may not have symptoms until they are adults.

Any activity or medical problem that increases pressure on the tissue in the belly wall and muscles may lead to a hernia, including:
Chronic constipation and pushing hard (straining) to have a bowel movement
Chronic cough
Cystic fibrosis
Enlarged prostate, straining to urinate
Extra weight
Fluid in the abdomen (ascites)
Heavy lifting
Peritoneal dialysis
Poor nutrition
Smoking
Overexertion
Undescended testicles
.


Symptoms

There are usually no symptoms. Some people have discomfort or pain. The discomfort may be worse when you stand, strain, or lift heavy objects. In time, most people will complain about a bump that is sore and growing.

If a hernia gets bigger, it may get stuck inside the hole and lose its blood supply. This is called "strangulation." If this occurs, you will need urgent surgery.

Treatment

Surgery is the only treatment that can permanently fix a hernia. Surgery may be more risky for patients with serious medical problems.

Surgery secures the weakened abdominal wall tissue (fascia) and closes any holes. Today, most hernias are closed with cloth patches to plug up the holes.

An umbilical hernia that does not heal on its own by the time your child is 5 years old may be repaired.

Emergency surgery is sometimes needed. The sac containing the intestine or other tissue may become stuck in the hole in the abdominal wall. If it cannot be pushed back through, this can lead to a strangulated loop of intestine. If left untreated, this portion of the intestine dies because it loses its blood supply.

Today, hernias can be fixed by open surgery or with the use of a laparoscope (camera). The advantages of using a camera include smaller surgical cuts, faster recovery, and less pain after the procedure.
.
Outlook (Prognosis)

The outcome for most hernias is usually good with treatment. It is rare for a hernia to come back. Incisional hernias are more likely to return.
.
Possible Complications

In rare cases, inguinal hernia repair can damage structures involved in the function of a man's testicles.

Another risk of hernia surgery is nerve damage, which can lead to numbness in the groin area.

If a part of your bowel was trapped or strangulated before surgery, it may lead to a bowel perforation or dead bowel.
.When to Contact a Medical Professional

Call your doctor right away if:
You have a painful hernia and the contents cannot be pushed back into the abdomen using gentle pressure
You develop nausea, vomiting, or a fever along with a painful hernia
You have a hernia that becomes red, purple, dark, or discolored

Call your doctor if:
You have groin pain, swelling, or a bulge
You have a bulge or swelling in the groin or belly button, or that is associated with a previous surgical cut.
.

Prevention
Use proper lifting techniques.
Lose weight if you are overweight.
Relieve or avoid constipation by eating plenty of fiber, drinking lots of fluid, going to the bathroom as soon as you have the urge, and exercising regularly.
Men should see their health care provider if they strain with urination. This may be a symptom of an enlarged prostate


Anonymous
Excellent resource! Really helped me get the gist of things.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags