我是在WIN CE下的 EVC编程,即为unicode系统的编程。CString str = "中国";
char temp[100];我试过GetBuffer(),当类型不匹配的时候也试过强制转换,可是temp中总不能得到正确的字符串。GetBuffer()返回的是 LPTSTR 类型数据,据我了解这是unicode的指针型,怎么才能转换成char*呢?先谢谢大家了!
char temp[100];我试过GetBuffer(),当类型不匹配的时候也试过强制转换,可是temp中总不能得到正确的字符串。GetBuffer()返回的是 LPTSTR 类型数据,据我了解这是unicode的指针型,怎么才能转换成char*呢?先谢谢大家了!
ASSERT(sizeof(temp)>str.GetLength());
strcat( temp, ( LPCTSTR )str );
temp[sizeof(temp) -1] = 0;
你的长度设置对了吗?
试试
str.GetBuffer(str.GetLength())
char szBuf[4];
CString s = L"中国";wcscpy( szUnicode, s );
strcpy( szBuf, szUnicode );
看来你并不真懂,请看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)短的时候拷贝已经终止了,怎么会访问到越界?
{
chararray(i)=str.GetAt(i);
}
如
CString myString("abc");
那么
myString[1]='b';只要用个循环语句就可以赋值了。循环的次数用CString.GetLength()确定