wchar_t在mac intel下就是UTF-32LE,所以
wchar_t wchar[] = L"汉字";
NSString *str = [[NSString alloc] initWithBytes:wchar length:
wcslen(wchar) encoding:NSUTF32LittleEndianStringEncoding];
在iPhone中wchar_t 是32位的,所以转化的时候需要用NSUTF32StringEncoding。
下面就是转化的代码:
NSString *string = @"中国";
wchar_t *str = (wchar_t *)[string cStringUsingEncoding:NSUTF32StringEncoding];
eg.
NSString *str = [[NSString alloc] initWithBytes:token->token().c_str() length:wcslen(token->token().c_str())*4 encoding:NSUTF32LittleEndianStringEncoding];
NSLog(@"str = %@",str);
------------------------------------------------------------------------------------------------------------------------
wchar_t * token = (wchar_t *)[ccTokencStringUsingEncoding:NSUTF32StringEncoding];