1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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