Thread: Access violation...

  1. #1
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787

    Access violation...

    I'm getting an access violation from this code:
    Code:
    cout<<card[x].name
        <<setw(30-namelen)<<setprecision(0)<<'%'
        <<card[x].interestRate
        <<setw(10)<<setprecision(2)<<'$'
        <<card[x].balance<<std::flush
        <<setw(10-balancelength(card[x].balance))<<'$'
        <<adjbal(card[x].balance,card[x].interestRate)<<endl;
    The program stops output right before the second '$', and in debugging sends me to streambuf, line 130:
    Code:
    char_type                    _M_pback[_S_pback_size];
    theres some comments a few lines above:
    Code:
    // Necessary bits for putback buffer management. Only used in
    // the basic _filebuf class, as necessary for the standard
    // requirements.  The only basic _streambuf member function that
    // needs access to these data members is in_avail...
    // NB: pbacks of over one character are not currenly supported
    I tried flushing the stream, but that didn't help... without debugging, the program runs to that point and gets killed by windows... I dont' really even know what this is trying to tell me, so I brought my question here...
    Last edited by major_small; 12-17-2003 at 11:58 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    <<card[x]balance<<std::flush

    You're missing the member access operator in that line. It should be:

    <<card[x].balance

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    sorry about that... that's there... just missed it while retyping the code into the post... heh

    I've narrowed it down a little more... it's something wrong with the setw() part... here's the function call that went into that:
    Code:
    int financeClass::balancelength(float balance)
    {
         int i=3;  //two decimal places and decimal
         while(balance>0)
         {
              i++;
              balance/=10;
         }
         return i;
    }
    Last edited by major_small; 12-18-2003 at 12:08 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >     while(balance>0)
    >     {
    >          i++;
    >          balance/=10;
    >     }
    Looks like an endless loop, considering balance is a float.

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    fixed it before I saw your post, but thanks anyway:
    Code:
    int financeClass::balancelength(float balance)
    {
         int i=3;  //two decimal places and decimal
         while(balance>0)
         {
              i++;
              balance=static_cast<int>(balance/10.0);
         }
         return i;
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Looks like a good solution, glad you got it working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  2. Access violation when reading a string.
    By Desolation in forum C++ Programming
    Replies: 16
    Last Post: 05-01-2007, 10:25 AM
  3. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  4. Help! CListCtrl access violation
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2003, 02:40 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 02:46 PM