C++ problem

Discussion in 'C++' started by BenShums, Jan 2, 2008.

  1. BenShums

    BenShums New Member

    Joined:
    Jan 1, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Okay, so, I know just posted a thread, but I promise I won't post anymore for a week or two.

    With that out of the way, here is my problem....


    When I run this code in Visual Studio 2008's debugger,

    string str = "string";
    int num = 28;
    multimap<string,int> mm;
    mm.insert(pair<string,int>(str, num));


    After mm.insert(pair<string,int>(str,num)); str gets set to "bad pointer", and num becomes a really humongous number. In addition my debugger shows that mm contains a thousand keys labeled "error". It's really weird because I #included <map>, and declared it perfectly and everything.

    Do you think it has something to do with my settings?

    Thanks


    ~Ben Shumway
     
  2. BenShums

    BenShums New Member

    Joined:
    Jan 1, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Okay, so I spent some time away from the computer to let my mind refresh. When I came back, I realized that in the code

    1: string str = "string";
    2: int num = 28;
    3: multimap<string,int> mm;
    4: mm.insert(pair<string,int>(str, num));

    str becomes a bad-pointer not when when it's inserted inside of mm, but when it's created on line 1.

    Why is this? I'm declaring the string perfectly fine, and I'm #including <string>.

    Any ideas would be mich appreciated.

    Thanks,

    ~Ben S.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice