A map of varying vectors

D

Dekker

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
 
T

TB

Dekker skrev:
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)

A simple solution, make two maps:

std::map<std::string, std::vector<std::string> > result_name;
std::map said:
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?

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top