C++ 如何连接CComBSTR和字符串?

C++ 如何连接CComBSTR和字符串?,c++,string,C++,String,如何连接CComBSTR和字符串 我试过这样做: CComBSTR a = "DEF"; CComBSTR strRequete = "ABC'" + a + "GHI"; //marked line 但我在一行标记上发现一个错误,告诉我: 错误:表达式必须具有整型或非作用域枚举类型 非常感谢 微软说: CComBSTR类是BSTR的包装器,BSTR是长度前缀字符串 要么你必须使用 或 bstr=CStringWLString2+bstr 微软说: CComBSTR类是BSTR的包装器,BST

如何连接CComBSTR和字符串

我试过这样做:

CComBSTR a = "DEF";
CComBSTR strRequete = "ABC'" + a + "GHI"; //marked line
但我在一行标记上发现一个错误,告诉我:

错误:表达式必须具有整型或非作用域枚举类型

非常感谢

微软说:

CComBSTR类是BSTR的包装器,BSTR是长度前缀字符串

要么你必须使用 或

bstr=CStringWLString2+bstr

微软说:

CComBSTR类是BSTR的包装器,BSTR是长度前缀字符串

要么你必须使用 或

bstr=CStringWLString2+bstr

.

要连接,您必须:

使用+=运算符,可以如下方式追加:

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"
更多类似于此链接的信息:

要连接,您必须:

使用+=运算符,可以如下方式追加:

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"

更多类似于此的信息,请访问此链接:

哪一种是最佳做法?@Luciekulza:您有6个采用不同类型的重载Append方法。一个需要CComBSTR的版本。因此,如果您想附加+号,则使用后者。在这种情况下没有最佳实践。Append对我来说更详细,可以看起来更好。你能提供一个像弗雷德里克·高斯那样的简短例子吗?@Luciekulza:例子在第二块。请看最后一个+=。感谢您的回答,请再问一个问题:要将CComBSTR转换为SQLWCHAR*,我是否需要简单地使用SQLWCHAR*strContent?哪一个是最佳做法?@Luciekulza:您有6个采用不同类型的重载Append方法。一个需要CComBSTR的版本。因此,如果您想附加+号,则使用后者。在这种情况下没有最佳实践。Append对我来说更详细,可以看起来更好。你能提供一个像弗雷德里克·高斯那样的简短例子吗?@Luciekulza:例子在第二块。请看最后一个+=。感谢您的回答,请再问一个问题:要将CComBSTR转换为SQLWCHAR*,是否只需要SQLWCHAR*strContent?