I have a pipe-delimited data file with more than 13 columns. The total file size is above 100 MB. I am reading each row, splitting the string into a std::vector<std::string>
so I can do calculations. I repeat this process for all the rows in the file like below:
string filename = "file.dat";
fstream infile(filename);
string line;
while (getline(infile, line)) {
string item;
stringstream ss(line);
vector<string> splittedString;
while (getline(ss, item, '|')) {
splittedString.push_back(item);
}
int a = stoi(splittedString[0]);
// I do some processing like this before some manipulation and calculations with the data
}
This is however very time consuming and I am pretty sure it is not the most optimized way of reading a CSV-type file. How can this be improved?
update
I tried using the boost::split
function instead of a while loop but it is actually even slower.