我是_bstr_t
的新手,仍然试图弄清楚它。我试图检查一个特定的字符串x
是否包含在bstring中的任何位置。我通常会喜欢的东西;如何检查_bstr_t是否包含(类似于str.find)字符串
String x = "hello";
String example = "You! hello there";
...
if (example.find(x) != string::npos) {
...
只是为了记录预期的平台是windows。
我是_bstr_t
的新手,仍然试图弄清楚它。我试图检查一个特定的字符串x
是否包含在bstring中的任何位置。我通常会喜欢的东西;如何检查_bstr_t是否包含(类似于str.find)字符串
String x = "hello";
String example = "You! hello there";
...
if (example.find(x) != string::npos) {
...
只是为了记录预期的平台是windows。
没有必要使用_bstr_t
。使用BSTR
类型。
接下来,阅读Eric's Complete Guide to BSTR Semantics。
最后,您可以在本机代码中使用BSTR,您将以普通字符数组的方式在大多数个案中使用。
BSTR bstr = SysAllocString(L"FooBarBazQux");
if (wcsstr(bstr, L"Bar") != NULL) {
// Found it! Do something.
} else {
// Not there.
}
SysFreeString(bstr);
你的例子似乎试图从STL中使用string :: find。但是你需要指定“String”类型的变量(大写)。如果你不是做的事:
using namespace std;
string x = "hello";
string example = "You! hello there";
...
您的例子编译。你真的有一个BSTR或_bstr_t,你需要与你没有显示的工作?即使这样,从_bstr_t开始生成一个std :: string也很容易,在这之后你可以像平常一样使用STL。
感谢您的帮助,但是编译器似乎不喜欢某事,'错误C2665:'wcsstr':2个重载都不能转换所有的参数类型......'const wchar_t * wcsstr(const wchar_t * ,const wchar_t *)'...'wchar_t * wcsstr(wchar_t *,const wchar_t *)' – pondigi
很难说没有看到您的代码。可能是一个'const'问题?您可以随时使用新代码提出新问题。 –
无论如何感谢哥们,虐待检查const – pondigi