如何在c++中构造嵌入NULL字符的BSTR
How can i construct BSTR with embedded NULL character in c++?
如何用嵌入的NULL字符构造BSTR?
使用传递null的SysAllocStringLen()
作为第一个参数来分配缓冲区,然后以任何方式填充正文。类似这样的东西:
BSTR bstr = SysAllocStringLength( 0, desiredLength );
if( bstr == 0 ) {
//handle error, get out of here
}
for( int i = 0; i < desiredLength; i++ ) {
if( i % 3 == 0 ) {
bstr[i] = 0;
} else {
bstr[i] = 'A';
}
}
短代码片段
BSTR HasNul = ::SysAllocStringLen(L"Who needs embedded like that?", 30);
std::wcout << L"Last character: " << HasNul[29] << " " << HasNul << L"n";
BSTR
的长度为30,所以最后一个字符是HasNul[29]
,在我的示例中是问号。输出为
Last character: ? Who needs
因为纯C++方法CCD_ 4在第一个NUL字符处停止。作为一个初学者,你真的需要这个吗?
相关文章:
- 将 NULL 与 C 的字符* 字符串一起使用
- 如何在 C++ 中使用 NULL(或 0)初始化静态字符数组
- 如何告诉字符串流忽略null终止字符
- 如何获取包含 NULL 字符的外壳代码字符串的长度
- 当使用反向循环逆转字符串时,null字符会发生什么
- NULL字符未出现在COUT中
- 将字符串指针与 NULL 以及 NULL 字符进行比较的目的
- 在std::字符串或字符数组中间包含NULL字符的UPDATE
- 打印超过 NULL 字符的内存内容
- 为什么编译器在每个字符串字面的C 的末端附加null字符
- 字符串长度函数w.r.t为null字符时的奇怪行为
- 在不使用c++中的库函数的情况下,计算不包括null字符的字符串长度
- 如何在c++中构造嵌入NULL字符的BSTR
- 如何在C++中将NULL字符嵌入字符串中
- 字符串中的null字符
- 为什么我不能在 C++ 中构造一个带有 NULL 字符* 的字符串?
- 加密数据中的Null字符
- Log4cxx宏无法使用包含null字符的字符串
- 为什么指向 NULL 字符的指针没有转换为 false
- 将字符串内带有 NULL 字符的字符串数据复制到字符数组