using map item without assigning onw first?

Discussion in 'C++' started by Gernot Frisch, Oct 28, 2004.

  1. Can I do this:

    std::map<long, std::vector<long>> snapmap;
    long i=4, j=0;
    snapmap[j].push_back(i);


    --
    -Gernot
    int main(int argc, char** argv) {printf
    ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

    ________________________________________
    Looking for a good game? Do it yourself!
    GLBasic - you can do
    www.GLBasic.com
     
    Gernot Frisch, Oct 28, 2004
    #1
    1. Advertising

  2. "Gernot Frisch" <> wrote in message
    news:...
    > Can I do this:
    >
    > std::map<long, std::vector<long>> snapmap;
    > long i=4, j=0;
    > snapmap[j].push_back(i);
    >


    Yes, using snapmap[j] will create a map entry using the default constructor
    for std::vector<long>. You then push back i onto that empty vector.

    john
     
    John Harrison, Oct 28, 2004
    #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. ittium
    Replies:
    4
    Views:
    317
    ittium
    Dec 8, 2011
  2. Justin C

    map an array but first item different?

    Justin C, Oct 21, 2010, in forum: Perl Misc
    Replies:
    5
    Views:
    116
    Uri Guttman
    Oct 25, 2010
  3. Roger
    Replies:
    4
    Views:
    242
    Roger
    Aug 21, 2005
  4. weston
    Replies:
    1
    Views:
    254
    Richard Cornford
    Sep 22, 2006
  5. Replies:
    0
    Views:
    213
Loading...

Share This Page