Access Violation!!! Help Plz

Started by
2 comments, last by Dark Piper 19 years, 4 months ago
Hi, I'm using trying to write a program for my C++ class that reads student records and outputs a lot of stuff about them. Everything's basically working except that when I try to output the honour roll students, failers and those who missed two or more assignments the compiler is giving me an error message: "An Access Violation (Segmentation Fault)raised in you program." On the line where I'm getting this I'm trying to output a vector location: cout << honour[j]
Advertisement
The line of code you showed tells me you're using a loop. My guess is, that you're reading outside of your array, in memory that's not yours. For instance, the following code will throw an access violation:

int IntArray[5] = {0, 1, 2, 3, 4 }; // Create array and fill it// Loop the array and display the values:for (int nLoop = 0; nLoop < 8; nLoop++){    cout << IntArray[nLoop] << endl;}


As you can see, there are only 5 items in the array, and the loop runs 8 times. The last 3 items are outside the array(Or, out of bounds in programmer talk). This will read memory that is not part of your program, and will crash your application.

Toolmaker

taking from toolmaker's point, you may have done this:

int IntArray[5] = {0, 1, 2, 3, 4 }; // Create array and fill it

// Loop the array and display the values:
for (int nLoop = 1; nLoop <=5; nLoop++)
{
cout << IntArray[nLoop] << endl;
}

this will also create an error, I used to do this all the time
ok thanks, all better

This topic is closed to new replies.

Advertisement