如何将Int转换为CString?

时间:2022-01-22 19:50:39

I can convert a Double to a CString using _ecvt

我可以使用_ecvt将Double转换为CString

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

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

那么,有没有像上面那样将int转换为CString的方法?

2 个解决方案

#1


48  

Here's one way:

这是一种方式:

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

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

在您的情况下,请尝试_T(“%d”)或L“%d”而不是“%d”

#2


5  

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:

如果你想要与你的例子更相似的东西,试试_itot_s。在Microsoft编译器上_itot_s指向_itoa_s或_itow_s,具体取决于您的Unicode设置:

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.

它应该稍快一些,因为它不需要解析输入格式。

#1


48  

Here's one way:

这是一种方式:

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

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

在您的情况下,请尝试_T(“%d”)或L“%d”而不是“%d”

#2


5  

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:

如果你想要与你的例子更相似的东西,试试_itot_s。在Microsoft编译器上_itot_s指向_itoa_s或_itow_s,具体取决于您的Unicode设置:

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.

它应该稍快一些,因为它不需要解析输入格式。