c++ - 如何连接CComBSTR和字符串?

标签 c++ string

如何连接CComBSTR和字符串?

我已经尝试过这种方法:

CComBSTR a = "DEF";
CComBSTR strRequete = "ABC'" + a + "GHI"; //marked line

但是我在标记行a上收到错误:

Error: expression must have integral or unscoped enum type.

非常感谢!

最佳答案

要连接,您有 8 methods :

HRESULT Append(LPCOLESTR lpsz, int nLen);             
HRESULT Append(LPCOLESTR lpsz);                       
HRESULT Append(LPCSTR);                               
HRESULT Append(char ch);                              
HRESULT Append(wchar_t ch);                           

HRESULT Append(const CComBSTR& bstrSrc);          
CComBSTR& operator+=(const CComBSTR& bstrSrc);

HRESULT AppendBSTR(BSTR p);  

使用 += 运算符,您可以像这样附加:

CComBSTR strSentence = OLESTR("Now is the time ");

// strSentence contains "Now is the time "
CComBSTR str11 (OLESTR("for all good men ");
// calls Append(const CComBSTR& bstrSrc);
strSentence.Append(str11);
// strSentence contains "Now is the time for all good men "
// calls Append(LPCOLESTR lpsz);
strSentence.Append((OLESTR("to come "));
// strSentence contains "Now is the time for all good men to come "
// calls Append(LPCSTR lpsz);
strSentence.Append("to the aid ");
// strSentence contains
// "Now is the time for all good men to come to the aid "

CComBSTR str12 (OLESTR("of their country"));
strSentence += str12; // calls operator+=()
// "Now is the time for all good men to come to
// the aid of their country"

更多类似信息请访问此链接:http://www.369o.com/data/books/atl/0321159624/ch02lev1sec3.html

关于c++ - 如何连接CComBSTR和字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22405721/

相关文章:

c++ - 如何在我的 C++ 项目中包含 SQLite DLL?

python - 如何在 Python 中使用 JSON 从文件的特定列表中检索特定字符串

java - 如何用Java中的字符串 '2'替换字符串中的字符 "to"?

python - 使用 setattr() 将字符串转换为变量

mysql - 如何在 mysql 列中查找和替换单词?

ios - 为什么我的数据没有通过 View Controller 传递?

c++ - 我想使用 set 删除重复元素并在插入时保持顺序

c++ - 使用 C++ 创建所有者绘制的菜单,2012 风格

c++ - 使用容器中元素的别名使用 std::list::remove 删除元素是否正确?

c++ - Turbo C++ 编译错误 "too many types in declaration"