gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 01:05:34 25 4
gpt4 key购买 nike

如何连接CComBSTR和字符串?

我试过这种方式:

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

但我在 marked linea 上收到错误消息:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com