所以我有一个2d向量vector<vector<string> tokensArray;
,我想把它的每个元素放到一个地图中:map<string, vector<string>> tokens;
。这样做的最快方法是什么?我希望map<*string*, vector<string>>
的字符串tokensArray[any number][0]
和map <string, *vector<string*>>
的矢量由tokensArray[any number][1, 2, 3, etc]
组成。
所以如果载体是:
vector<vector<string> tokensArray = { {"hello", "person", "word"} {"bye", "people", "sentence"} }
地图应该像:
map<string, vector<string>> tokens;
tokens["hello"] = {"person", "word"};
tokens["bye"] = {"people", "sentence"};
答案 0 :(得分:0)
map<string, vector<string>> tokens;
for (auto &v : input) {
if (v.size() > 1) {
tokens[v[0]] = vector<string>(v.begin() + 1, v.end()); // Create a new vector copy starting from second index.
}
}