I've got a map<string, vector<uint64>>
and a csv file of such format:
STARTX,20000000,WIDTH,20,COUNT,1000000
ROW,4,COL,55
ROW,5,COL,20
ROW,9,COL,20
ROW,12,COL,85
ROW,14,COL,8
I'm wondering what would be the best way of splitting all string values and adding them to the map as keys and adding the next integer value to the vector corresponding to the key(the preceding string value) using streams. The following code sample does not do the job correctly.
std::istringstream iss(stringRes);
std::string word;
uint64_t val;
while (std::getline(iss, word, ',') >> std::ws)
{
/* do stuff with word */
if (result.find(word) == result.end()) //word not found in map
{
std::vector<uint64_t> newV;
result.insert(
std::pair<std::string, std::vector<uint64_t>>(word, newV));
}
iss >> val;
result[word].push_back(val);
}