Я делаю парсер файлов для файлов OBJ, и все идет в нужное место, но по какой-то причине оно не запускается до конца файла.C++ OBJ file parser
void loader::readIn()
{
//!takes in the all the data and
//!puts in string first.
std::string line;
while(!myFile.eof())
{
linetype = unknown;//enum set to uknown
line.clear(); // clear line
ss.clear(); // clear string stream
std::getline(myFile,line); //intake line , to string line
//found = line.find("v "); //enum to check the line type i,e Face ,vertex
if(line[0] == 'v') //! check to see if the first char is v
{
linetype = vertex;
}
// found = line.find("f ");
if(line[0] == 'f') //! checkl to see if the first char is f
{
linetype = face;
}
// found = line.find("vn ");
if(line[0] == 'vn') //! checkl to see if the first char is vn
{
linetype = vertexNormal;
}
// found = line.find("vt ")
if(line[0] == 'vt') //! checkl to see if the first char is vt
{
linetype = vertexTexture;
}
if(line[0] == ' ' || '#') // if the start of the line is empty or a #
{
line.clear(); //clear line
std::getline(myFile,line); // intake the next line
}
switch(linetype)
{
case vertex: //!stores the verrtex floats in vert.
ss >> vertexFloat[0] >> vertexFloat[1] >> vertexFloat[2];
verts.push_back(new coordinate(vertexFloat[0],vertexFloat[1],vertexFloat[2])); //creates new coord
linetype = unknown;
break;
case face:
int n; // these are the counters for the float arrays
int m;
int b;
n = 0;
m = 0;
b = 0;
int faces[3]; //temperary float array
int faceText[3];
int faceNorm[3];
ss.str(line); //string stream intake line
ss.ignore(1);
while(!ss.eof())
{
ss >> faces[n]; // intake first umber
n++;
if(ss.peek() == '/')
{
ss.ignore(1);
if(ss.peek() != '/')
{
ss >> faceText[m];
m++;
}
}
ss.ignore(1);
ss >> faceNorm[b];
b++;
}
for(int i = 0; i < 3 ; ++i)
{
totalFaces.push_back(faces[i]); // push back all the ints on the correct
faceTexture.push_back(faceText[i]); // vector
faceNormal.push_back(faceNorm[i]);
}
break;
Это код, который требуется в первых трех строках, затем просто останавливается. Я проверяю вектор totalFaces, который принимает первое число каждого набора из 3.
**f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9
f 1/2/3 4//6 7/8/9**
- это мой файл obj.
Вы можете использовать while (std :: getline (myFile, line)) {.. ваш код здесь ..} –