我的代码:
int iLen2=0;
iLen=WideCharToMultiByte(CP_ACP,0,data.GetBuffer(),data.GetLength(),0,0,0,0);这里返回的ilen有没有包含结束符啊?我测试了一下,貌似没有包含呀

解决方案 »

  1.   

    data是什么?结束符是指的0?
      

  2.   

    那我在new的时候是不是应该char* buf=new char[ilen+1]啊?我在程序里没有+1,貌似也是正常的。
    迷糊迷糊~~
      

  3.   

    Returns the number of bytes written to the buffer pointed to by lpMultiByteStr if successful. The number includes the byte for the terminating null character.
    这里说的很清楚了,返回值里包含了空字符,new的时候不用+1
      

  4.   


    这个我看过了但是
    我cstring里的内容是_T("123"),它返回的值是3,这个就让我很迷惑。如果包含空字符,那应该是4才对吧
      

  5.   

    你好呀,我查过了这个应该是不包含'\0'的。Returns the number of bytes written to the buffer pointed to by lpMultiByteStr if successful.再说+1没坏处,最好是+2
      

  6.   


    new出来的东西溢出一两个字节很难发现的
      

  7.   


    http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx
      

  8.   

    谢谢楼上的,不过你没看后面半句The number includes the byte for the terminating null character.
      

  9.   

    你在哪里看的MSDN,微软最新的:
    Return ValueReturns the number of bytes written to the buffer pointed to by lpMultiByteStr if successful. If the function succeeds and cbMultiByte is 0, the return value is the required size, in bytes, for the buffer indicated by lpMultiByteStr.The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:    ERROR_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.
        ERROR_INVALID_FLAGS. The values supplied for flags were not valid.
        ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.
        ERROR_NO_UNICODE_TRANSLATION. Invalid Unicode was found in a string.