A map of varying vectors

Discussion in 'C++' started by Dekker, Mar 21, 2006.

  1. Dekker

    Dekker Guest

    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
    Dekker, Mar 21, 2006
    #1
    1. Advertising

  2. Dekker

    TB Guest

    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<std::string, std::vector<int> > result_age;

    > 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?

    --
    TB @ SWEDEN
    TB, Mar 21, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo

    Map for Vectors

    Marcelo, Jan 30, 2006, in forum: Java
    Replies:
    2
    Views:
    351
    Roedy Green
    Jan 30, 2006
  2. Juicer_X

    Re: Map of vectors how? <Long>

    Juicer_X, Nov 25, 2004, in forum: C++
    Replies:
    0
    Views:
    400
    Juicer_X
    Nov 25, 2004
  3. Replies:
    3
    Views:
    260
    Daniel T.
    Aug 15, 2006
  4. Replies:
    3
    Views:
    667
    Shadowman
    Mar 26, 2008
  5. Guest
    Replies:
    0
    Views:
    415
    Guest
    Sep 14, 2005
Loading...

Share This Page