如何连接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/