int转string.
我用
CString y;
int t;
y.Format("%d",t);这样为什么不行?平台用的不是vc,是.net下的mfc,有关系么?
如果在.net下怎么写?

解决方案 »

  1.   

    最好能说明一下 .net 下报了什么错, 以便最快最准确的回答你的问题 .
      

  2.   

    如果只是写:
    CString y;
    int t;
    y.Format("%d",t);
    这是不行的, 因为这里的 t 没有初始化, .net 的检查比较严格.
      

  3.   

    初始化过了错误是这样的
    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
      

  4.   

    改为:
    CString y;
    int t = 0;
    y.Format(_T("%d"),t);
    // AfxMessageBox(y);因为你使用 Unicode 库(N)
      

  5.   

    已经解决
    再问个很弱的问题.y.Format(_T("%d"),t);后怎么y的值没变?
      

  6.   

    y.Format(_T("%d"),t);后y的值是什么?
    应该是0;
    不知道你要什么呢?