Debug Assertion Failure?

G

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?
 
I

Ian Collins

Gone said:
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++.
 
J

James Kanze

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.)
 
G

Gone With Wind

* 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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top