initial value of pointer value in std map ?

Discussion in 'C++' started by PGK, Apr 2, 2009.

  1. PGK

    PGK Guest

    If I use std::map with pointer values, can I assume they will have an
    initial value of zero, when I use the [] operator on a key that
    doesn't exist? For example, will this:

    map<int, fstream *> m;
    cout << m[123];

    always output a zero/NULL/0?

    Thanks,
    Paul
     
    PGK, Apr 2, 2009
    #1
    1. Advertising

  2. PGK

    ZikO Guest

    PGK wrote:
    > If I use std::map with pointer values, can I assume they will have an
    > initial value of zero, when I use the [] operator on a key that
    > doesn't exist? For example, will this:
    >
    > map<int, fstream *> m;
    > cout << m[123];
    >
    > always output a zero/NULL/0?
    >
    > Thanks,
    > Paul


    Yes, it will initialize fstream pointer with zero. The same would happen
    with simple int, int* etc.
     
    ZikO, Apr 2, 2009
    #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. Peter Jansson
    Replies:
    5
    Views:
    6,425
    Ivan Vecerina
    Mar 17, 2005
  2. Chris Forone

    std::valarray as value in std::map

    Chris Forone, Nov 3, 2007, in forum: C++
    Replies:
    5
    Views:
    396
    Pete Becker
    Nov 5, 2007
  3. Replies:
    1
    Views:
    451
    red floyd
    Dec 21, 2008
  4. Thomas J. Gritzan
    Replies:
    6
    Views:
    1,049
    James Kanze
    Dec 22, 2008
  5. James Kanze
    Replies:
    0
    Views:
    2,066
    James Kanze
    Dec 21, 2008
Loading...

Share This Page