Connecting Tech Pros Worldwide Forums | Help | Site Map

A map of varying vectors

Dekker
Guest
 
Posts: n/a
#1: Mar 21 '06
Hi

I would like to transform the result of a csv-string (eg.:
"name,age\nstring,int\nMac,23\nMax,24\nMike,78 ") into a map of vectors
map<string, vector<???> >.

The key of the map will be the fieldname (name or age) and the values
are stored as vectors in the indicated type (string, int). Like this i
can call: result["name"][0] (= a string "Mac") or result["age"][0] (=
an int of val 23)

The problem I have: I would like to store the age as int the name as
string. How can I define a map with varying vectors?

Minor problem: Does the STL have a tokeninzing/splitting utiltiy for
strings?

Thanks in advance,
Marco

TB
Guest
 
Posts: n/a
#2: Mar 21 '06

re: A map of varying vectors


Dekker skrev:[color=blue]
> Hi
>
> I would like to transform the result of a csv-string (eg.:
> "name,age\nstring,int\nMac,23\nMax,24\nMike,78 ") into a map of vectors
> map<string, vector<???> >.
>
> The key of the map will be the fieldname (name or age) and the values
> are stored as vectors in the indicated type (string, int). Like this i
> can call: result["name"][0] (= a string "Mac") or result["age"][0] (=
> an int of val 23)
>[/color]

A simple solution, make two maps:

std::map<std::string, std::vector<std::string> > result_name;
std::map<std::string, std::vector<int> > result_age;
[color=blue]
> The problem I have: I would like to store the age as int the name as
> string. How can I define a map with varying vectors?
>
> Minor problem: Does the STL have a tokeninzing/splitting utiltiy for
> strings?
>[/color]

You mean like all those member functions of std::string?

--
TB @ SWEDEN
Closed Thread