我是在WIN CE下的 EVC编程,即为unicode系统的编程。CString str = "中国";
char temp[100];我试过GetBuffer(),当类型不匹配的时候也试过强制转换,可是temp中总不能得到正确的字符串。GetBuffer()返回的是 LPTSTR 类型数据,据我了解这是unicode的指针型,怎么才能转换成char*呢?先谢谢大家了!

解决方案 »

  1.   

    很简单:strcpy(temp,(LPCTSTR)str);
    ASSERT(sizeof(temp)>str.GetLength());
      

  2.   

    strcpy(temp, (LPTSTR)(LPCTSTR)str);
      

  3.   

    memset( temp, 0, 100 );
    strcat( temp, ( LPCTSTR )str );
      

  4.   

    严格地说,应该是这样:char temp[...];strncpy(temp, (LPCTSTR)str, sizeof(temp));
    temp[sizeof(temp) -1] = 0;
      

  5.   

    to oldworm(oldworm) 你这样也不完善,有可能会出现读越界错误。(LPCTSTR)str可能比sizeof(temp)小,读越界有时候会导致系统异常:内存不可读。
      

  6.   

    LPTSTR不是unicode的指针,LPCWSTR才是。
    你的长度设置对了吗?
    试试
    str.GetBuffer(str.GetLength())
      

  7.   

    UNICODE用wchar_t来装.wchar_t szUnicode[2];
    char    szBuf[4];
    CString s = L"中国";wcscpy( szUnicode, s );
    strcpy( szBuf, szUnicode );
      

  8.   

    to stonespace(stonespace) :
    看来你并不真懂,请看strncpy实现:
    char * __cdecl strncpy (
            char * dest,
            const char * source,
            size_t count
            )
    {
            char *start = dest;        while (count && (*dest++ = *source++))    /* copy string */
                    count--;        if (count)                              /* pad out with zeroes */
                    while (--count)
                            *dest++ = '\0';        return(start);
    }当str比sizeof(temp)短的时候拷贝已经终止了,怎么会访问到越界?
      

  9.   

    LPTSTR只有定义了_UNICODE才是wchr_t*, 否则是char*.
      

  10.   

    for(int i=0;i<str.GetLength();i++)
    {
      chararray(i)=str.GetAt(i);
    }
      

  11.   

    CString有重载符号[]

    CString myString("abc");
    那么
    myString[1]='b';只要用个循环语句就可以赋值了。循环的次数用CString.GetLength()确定
      

  12.   

    去看看专家的建议~~~http://www.pgh.net/~newcomer/cstring.htm