I am trying to read a text file with different amount of variables on each line and set the correct values to a vector using sstream.
/*Example file
"f 1 2 3"
"f 4 5 6 7" */
ifstream infile(file);
string line;
char a;
int i=0;v,x,y,z;
while(getline(infile,line))
{
istringstream iss(line)
if(line[0]=='f')
{
if(iss>> a >> v >> x >> y)
{
poly[i].face[0]=v;
poly[i].face[1]=x;
poly[i].face[2]=y;
poly[i].four=false;
}
else if(iss>> a >> v >> x >> y >> z) //this doesn't seem to get called, ever.
{
poly[i].face[0]=v;
poly[i].face[1]=x;
poly[i].face[2]=y;
poly[i].face[3]=z;
poly[i].four=true;
}
poly.push_back(Poly());
i++;
}
}
code works for lines with 3 variables, but not for lines with 4 variables.