Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 转换;wstring";至;const UInt8*”;_C++_Xcode_Macos_Unicode_Wstring - Fatal编程技术网

C++ 转换;wstring";至;const 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转换为(UInt8*)。 还有,我有一根绳子:

    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。。。。很抱歉