I have my code written and it can be compile successfully. Not sure where the problem is (I checked the pointer part, it should be fine). I highlighted the part in bold which I think might cause the problem. Thanks a lot !
while (ss >> buf)
tokens.push_back(buf); // Not sure about this part;
double score[4]; // Create a double array to contain all the 4 scores in each line;
double total=0; // to calculate the total of 4 scores for each student;
string grade;
int Total;
for (int i=0; i<4; i++){
score[i] = atof (tokens[i+1].c_str()); // convert each score in string type into double type and copy into the array
total += score[i]; // calculate the total of 4 scores;
}
Total = int (total); // convert the total in double type into integer;
I'd really appreciate it if you used [code] blocks so that I could give you line numbers.
Your segmentation fault probably doesn't occur in any of the bolded lines, but most likely in the loop just after it. Do you see the problem you have with the index when you're using the vector's []?
score[i] = atof (tokens[i+1].c_str()); // convert each score in string type into double type and copy into the array will crash (segmentation fault) when tokens.size() < 5