How can I convert an Int to a CString?

110,534

Solution 1

Here's one way:

CString str;
str.Format("%d", 5);

In your case, try _T("%d") or L"%d" rather than "%d"

Solution 2

If you want something more similar to your example try _itot_s. On Microsoft compilers _itot_s points to _itoa_s or _itow_s depending on your Unicode setting:

CString str;
_itot_s( 15, str.GetBufferSetLength( 40 ), 40, 10 );
str.ReleaseBuffer();

it should be slightly faster since it doesn't need to parse an input format.

Share:
110,534
Eslam Hamdy
Author by

Eslam Hamdy

Senior engineer with +9 years experience in java ecosystem, have one plus year experience in crafting and managing agile teams, has a passion for nature, mountain biking, swimming, traveling, tensegrity and coding.

Updated on August 26, 2021

Comments

  • Eslam Hamdy
    Eslam Hamdy over 2 years

    I can convert a Double to a CString using _ecvt

    result_str=_ecvt(int,15,&decimal,&sign);
    

    So, is there a method like the one above that converts an int to CString?