Hello everyone.
I wrote a code to read a txt file with specified number of column into a vector of vector. This text file has two part, the first part starts and ends with this expression, Coordinates and end coordinates. the start and end line for the second part is elements and and elements. in this case I know the number of column but I want to change the code in a way that read the mesh for unknown number of colmun. I don;t want to use something like while (is >> ID >> x >> y >> z)
here is txt and code,
change it to push backs, along the lines of:
while(is >> tmp)
data.push back (tmp)
if you know the type, eg all numbers and all -1 then push back tmp-1 into a vector of numbers.
if its a mix of text and such you will have to push into a vector of strings and parse those somehow, with some rules based off the file data and what you know about it.
and, you have a 2-d construct, right? rows/lines each with columns of stuff..!
so the logic would be:
for(lines)
{
for(is>>elem)
{
tmp.push_back(elem);
}
line.push_back(tmp); //push a vector of data, eg 1 2 3 4 onto a vector of lines from file
tmp.clear() //clear this or it will keep growing, appending each line's junk to the previous line's junk
}
if you need more than a simple exclude first, you can provide a blacklist of columns to skip. One way is a vector of <bool> for skip/use in each spot. If you run off the end of the vector, you can choose to default keep/discard the rest by default.
eg vector<bool> blacklist(true,10);
blacklist[0] = false;
blacklist[6] = false;
...
in your loops
if(current_index >= blacklist.size() || blacklist[current_index])
push-back
else
do nothing
What file format is this?
It might be worth your time to use something like Wavefront OBJ — very easy to handle and almost all 3D libraries can read it.