Debug Assertion Failure?

Discussion in 'C++' started by Gone With Wind, May 25, 2008.

  1. I am a novice of C++. I write the following code to append strings to
    a Combox (m_RibNum). This control component is on a PropertyPage
    hosted on a PropertySheet.

    int i;
    char buffer[10];
    CString s
    for (i=0;i<5;i++)
    {
    itoa(i+1,buffer,10);
    s=*buffer;
    sheet.m_RibTypeEdit.m_RibNum.AddString((LPCTSTR)s);
    }

    When I debug this code, Debug Assertion Failure occured. Could anybody
    tell me what's wrong in my code please?
     
    Gone With Wind, May 25, 2008
    #1
    1. Advertising

  2. Gone With Wind

    Ian Collins Guest

    Gone With Wind wrote:
    > I am a novice of C++. I write the following code to append strings to
    > a Combox (m_RibNum). This control component is on a PropertyPage
    > hosted on a PropertySheet.
    >
    > int i;
    > char buffer[10];
    > CString s
    > for (i=0;i<5;i++)
    > {
    > itoa(i+1,buffer,10);
    > s=*buffer;
    > sheet.m_RibTypeEdit.m_RibNum.AddString((LPCTSTR)s);
    > }
    >

    You'd have better luck on a windows group, none of those functions or
    classes are standard C++.

    --
    Ian Collins.
     
    Ian Collins, May 25, 2008
    #2
    1. Advertising

  3. Gone With Wind

    James Kanze Guest

    On May 25, 1:51 am, Gone With Wind <> wrote:
    > I am a novice of C++. I write the following code to append strings to
    > a Combox (m_RibNum). This control component is on a PropertyPage
    > hosted on a PropertySheet.


    > int i;
    > char buffer[10];
    > CString s
    > for (i=0;i<5;i++)
    > {
    > itoa(i+1,buffer,10);
    > s=*buffer;
    > sheet.m_RibTypeEdit.m_RibNum.AddString((LPCTSTR)s);
    > }


    > When I debug this code, Debug Assertion Failure occured. Could
    > anybody tell me what's wrong in my code please?


    As others have already pointed out, there's not much C++ in
    there to go on. Just guessing about what the code does,
    wouldn't something like:

    for ( int i = 0 ; i < 5 ; ++ i ) {
    std::istringstream s ;
    s << i ;
    shee.m_RibTypeEdit.m_RibNum.AddString(
    toCString( s.str() ) ) ;
    }

    be more what you are looking for. (I'm not too sure about how
    to convert a string to a CString, but if CString is some sort of
    text string, there's a good chance that CString( s.str().c_str() ), or
    even just CString( s.str() ) would do the trick here.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, May 25, 2008
    #3
  4. On May 25, 4:47 am, "Alf P. Steinbach" <> wrote:
    > * Gone With Wind:
    >
    >
    >
    >
    >
    > > I am a novice of C++. I write the following code to append strings to
    > > a Combox (m_RibNum). This control component is on a PropertyPage
    > > hosted on a PropertySheet.

    >
    > > int i;
    > > char buffer[10];
    > > CString s
    > > for (i=0;i<5;i++)
    > > {
    > >   itoa(i+1,buffer,10);
    > >   s=*buffer;
    > >   sheet.m_RibTypeEdit.m_RibNum.AddString((LPCTSTR)s);
    > > }

    >
    > > When I debug this code, Debug Assertion Failure occured. Could anybody
    > > tell me what's wrong in my code please?

    >
    > One thing that's wrong is that this code is not copied and pasted, so all we
    > know is that it's certainly not the exact code you have problems with.
    >
    > CString is not a standard C++ class, it's a class defined by Microsoft.
    >
    > Presumably your code could "work" if you changed it as follows:
    >
    >     for( int i = 1;  i <= 5;  ++i )
    >     {
    >         char buffer[10];
    >         itoa( i, buffer, 10 );
    >         sheet.m_RibTypeEdit.m_RibNum.AddString( buffer );
    >     }
    >
    > But it might be that e.g. it's the "sheet" variable that's causing problems.
    >
    > For more information post to a Windows programming group.
    >
    > Cheers, & hth.,
    >
    > - Alf
    >
    > --
    > A: Because it messes up the order in which people normally read text.
    > Q: Why is it such a bad thing?
    > A: Top-posting.
    > Q: What is the most annoying thing on usenet and in e-mail?- Hide quoted text -
    >
    > - Show quoted text -


    Thank you all for your help! I will move this to Windows programming
    group. :)
     
    Gone With Wind, May 25, 2008
    #4
    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. Kostatus

    Debug assertion failure

    Kostatus, Aug 3, 2003, in forum: C++
    Replies:
    1
    Views:
    2,897
    Gianni Mariani
    Aug 3, 2003
  2. Todd Miller

    gc assertion failure

    Todd Miller, Oct 29, 2003, in forum: Python
    Replies:
    3
    Views:
    484
    Michael Hudson
    Oct 30, 2003
  3. Tim Peters

    RE: gc assertion failure

    Tim Peters, Oct 29, 2003, in forum: Python
    Replies:
    3
    Views:
    693
    Todd Miller
    Oct 29, 2003
  4. Yang
    Replies:
    1
    Views:
    282
    Christophe
    Oct 27, 2006
  5. Replies:
    22
    Views:
    1,296
    Richard Heathfield
    Jun 19, 2007
Loading...

Share This Page