0

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);
    }
LogicStuff
  • 19,397
  • 6
  • 54
  • 74
  • TLDR: there's still `;` in the stream after `iss >> val;`. – LogicStuff Mar 20 '18 at 11:57
  • that's off-topic but are you sure that it's a map you wanna be using? because I see you have multiple ROW entries and multiple COL. If using a map only the first one of each will be entered. If that's not the behaviour you want maybe use something like a vector of pairs. – Adham Zahran Mar 20 '18 at 12:02

0 Answers0