Ok so basically I have this text file with numbers and letters that’s supposed to represent the vertices of a polygon. This part isn’t important because I’m having trouble parsing from the file into an int. So far the function looks like:
void parseModel(void)
{
int num_vertices, num_faces;
char data[255];
ifstream ifs("rect-skinny.d");
ifs.getline(data, 255);
istrstream ins(data);
ins >> num_vertices;
cout << num_vertices << endl;
ifs.close();
}
I’ve tried many different methods that all gave me different but incorrect answers. This one outputs the number -858993460 for some reason. Other times it would just output closed brackets when I would try to print data separately. I can’t figure out what I’m doing wrong since this seems like it should work. The input file is:
data 8 6
-0.5 1.0 0.3
0.5 1.0 0.3
0.5 -1.0 0.3
-0.5 -1.0 0.3
-0.5 1.0 -0.3
0.5 1.0 -0.3
0.5 -1.0 -0.3
-0.5 -1.0 -0.3
4 1 2 3 4
4 1 5 6 2
4 2 6 7 3
4 5 8 7 6
4 1 4 8 5
4 3 7 8 4
Basically all I’m trying to do right now is get the first line and put those numbers int it into num_vertices and num_faces, respectively.
After you read the text string “data” it will contain “
data 8 6“.The line
ins >> num_vertices;will try to read an integer, but will find “data 8 6” and so will fail. Try something like this: