C++ 转换;wstring";至;const UInt8*”;
我必须将wstring转换为(UInt8*)。 还有,我有一根绳子:C++ 转换;wstring";至;const UInt8*”;,c++,xcode,macos,unicode,wstring,C++,Xcode,Macos,Unicode,Wstring,我必须将wstring转换为(UInt8*)。 还有,我有一根绳子: wstring str; 你能帮我转换一下吗? 我尝试了此代码,但不起作用: wstring str; uint8 *buf = reinterpret_cast<uint8>(str); CFStringRef CFStringCreateWithBytes (CFAllocatorRef alloc,
wstring str;
你能帮我转换一下吗?
我尝试了此代码,但不起作用:
wstring str;
uint8 *buf = reinterpret_cast<uint8>(str);
CFStringRef CFStringCreateWithBytes (CFAllocatorRef alloc,
const UInt8 *buf,
CFIndex sizeOfBuf,
CFStringEncoding encoding,
Boolean isExternalRepresentation);
wstring-str;
uint8*buf=重新解释铸件(str);
CFStringRef CFStringCreateWithBytes(CFAllocatorRef alloc,
const UInt8*buf,
CFIndex sizeOfBuf,
CFSTRING编码,
布尔isExternalRepresentation);
wchar\u t
在OSX上是32位的,因此std::wstring
可以保存UTF-32编码字符串:
std::wstring str = ...;
CFStringRef encoded = CFStringCreateWithBytes(
kCFAllocatorDefault,
reinterpret_cast<uint8*>(str.c_str()),
str.size() * sizeof(wchar_t),
kCFStringEncodingUTF32LE,
false);
std::wstring str=。。。;
CFStringRef encoded=CFStringCreateWithBytes(
KCO默认值,
重新解释铸造(str.c_str()),
str.size()*sizeof(wchar_t),
kCFStringEncodingUTF32LE,
假);
为什么要这样做?std::wstring
由wchar\u t
s组成,它们应该大于uint8
s,并且很可能包含不同编码的字符串。@Biffen,我想要它,因为我想将参数“str”传递给函数,函数需要UInt32*buf。。。CFStringRef CFStringCreateWithBytes(CFAllocatorRef alloc,const UInt8*字节,CFIndex numBytes,CFStringEncoding编码,布尔isExternalRepresentation)<代码>UInt32或UInt8
?!此函数需要哪种编码?这与您的std::wstring str
编码相同吗?如果它们是相同的,您可以使用指向str
数据的指针(提示:str.c_str()
),否则您必须首先转换它,这不是特别简单的。当然,UInt8。。。。很抱歉