none
convert from type CString to type int.

    Question

  •  There is an error :error C2664: 'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'

    m_iMath = atoi(m_ctlList.GetItemText(index, 3));

    If i change it to "m_iMath = atoi(m_ctlList.GetItemText(index, 3).GetBuffer());
     
    another error would occurred:'atoi' : cannot convert parameter 1 from 'wchar_t *' to 'const char *'

    How to realize the converting?
    Sunday, December 21, 2008 2:34 AM

Answers

  • Both errors are telling you that your strings are not char they are wchar_t.  That happens when your project is set to use unicode strings, which is the default setting nowadays.

    So you can't use atoi.  It only works with chars.

    Use _ttoi and it will work in both unicode projects and MBCS/char/ASCII projects.

    And, you don't need the GetBuffer().

    m_iMath = _ttoi(m_ctlList.GetItemText(index, 3));

    (That's _ttoi with an underscore in front of it. This forum likes to drop underscores.)

    • Proposed as answer by ildjarn Sunday, December 21, 2008 5:51 AM
    • Marked as answer by cutedevil Sunday, December 21, 2008 8:59 AM
    Sunday, December 21, 2008 2:52 AM