I have a couple of ~3MB textfiles that I need to parse in C++.
The text file looks like this (1024x786
):
12,23 45,78 90,12 34,56 78,90 ...
12,23 45,78 90,12 34,56 78,90 ...
12,23 45,78 90,12 34,56 78,90 ...
12,23 45,78 90,12 34,56 78,90 ...
12,23 45,78 90,12 34,56 78,90 ...
means "number blocks" separated by Tab
, and the numbers itself containing a ,
(insted of a .
) decimal marker.
First of all I need to read the file. Currently I'm using this:
#include <boost/tokenizer.hpp>
string line;
ifstream myfile(file);
if (myfile.is_open())
{
char_separator<char> sep("\t");
tokenizer<char_separator<char>> tokens(line, sep);
}
myfile.close();
which is working nice in terms of getting me the "number block" but I still need to convert this char
to an float but handling the ,
as a decimal marker. Due to the filesize I think its not a good idea to tokenize
this as well. Further I need to add all this values to an data structure that I can access afterwards by location (e.g. [x][y]
). Any ideas how to fulfil this?