问一个类型转换的问题int to string int转string.我用CString y;int t;y.Format("%d",t);这样为什么不行?平台用的不是vc,是.net下的mfc,有关系么?如果在.net下怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最好能说明一下 .net 下报了什么错, 以便最快最准确的回答你的问题 . 如果只是写:CString y;int t;y.Format("%d",t);这是不行的, 因为这里的 t 没有初始化, .net 的检查比较严格. 初始化过了错误是这样的c:\documents and settings\liyuan\my documents\visual studio 2005\projects\csma\csma\csmadlg.cpp(304) : error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *' with [ BaseType=wchar_t, StringTraits=StrTraitMFC_DLL<wchar_t> ] Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 改为: CString y; int t = 0; y.Format(_T("%d"),t); // AfxMessageBox(y);因为你使用 Unicode 库(N) 已经解决再问个很弱的问题.y.Format(_T("%d"),t);后怎么y的值没变? y.Format(_T("%d"),t);后y的值是什么?应该是0;不知道你要什么呢? 去掉窗口标题栏,怎么实现? 如何获得一个USB程序和一个配套USB设备间传输的信息? 菜鸟问题:如何在oracle中用ado动态添加或者删除表的中的字段。 使用ADO调用存储过程的奇怪问题 VERY简单的问题. 为什么CSocket不能在线程之间传递?还有哪些MFC类不能在线程之间传递? 如何使用animateCtrl控件,播放 怎么样创建一个在隐藏的对话框? 求vc源码,关于媒体播放器的,要能够播放各种格式的声音、视频文件(最好用mcisendstring做)。 求教:怎样才能得到Outlook Express对象或者地址簿(wab)对象 消息的概念 怎么生成一个这样的按钮
CString y;
int t;
y.Format("%d",t);
这是不行的, 因为这里的 t 没有初始化, .net 的检查比较严格.
c:\documents and settings\liyuan\my documents\visual studio 2005\projects\csma\csma\csmadlg.cpp(304) : error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC_DLL<wchar_t>
]
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
CString y;
int t = 0;
y.Format(_T("%d"),t);
// AfxMessageBox(y);因为你使用 Unicode 库(N)
再问个很弱的问题.y.Format(_T("%d"),t);后怎么y的值没变?
应该是0;
不知道你要什么呢?