I have a vector that contains data like:
std::vector<std::string> v;
v[0] = "first:tom";
v[1] = "last:jones";
and I want to iterate through the vector and parse at : and put results in a std::map
std::vector<std::string> v;
std::map<std::string, std::string> m;
std::pair<std::string, std::string> p;
for(int i = 0; i < v.size(); i++)
{
std::cout << v[i] << std::endl;
std::istringstream oss(v[i]);
std::string token;
while(getline(oss, token, ':'))
{
m.insert(std::pair<std::string, std::string>("", ""));
}
}
I am stuck on insertion to the std::map because I dont see how the parse gives me both pieces that I can insert into the map.
It isn't v[i] in both.
I want:
m.insert(std::pair<std::string, std::string>("first", "tom"));
m.insert(std::pair<std::string, std::string>("last", "jones"));
Can anyone explain my difficulty?