所以我有这个结构:
struct foo{
DWORD fooB;
char *fooA;
}
并且我有一个变量DWORD bar;
,那么如何查找是否bar
与fooB
我的结构中的任何匹配?
编辑:我的代码(当前)
#include <algorithm> // for. std::find
using namesapce std;
struct foo{
DWORD fooB;
char *fooA;
// .... Use this
}
vector <DWORD> foo;
if ( std::find(vector.begin(),
vector.end(), pIdToFind) !=
vector.end() )
// We found the item in the list, so let's just continue
else
// We haven't found it,
您可以简单地提供一个比较运算符来将DWORD
s 与foo
s进行比较:
#include <vector>
#include <algorithm>
#include <windows.h>
struct foo {
DWORD fooB;
char *fooA;
};
bool operator==(DWORD lhs, foo const &rhs)
{
return lhs == rhs.fooB;
}
int main()
{
foo needle{ 42, nullptr };
vector<DWORD> haystack;
if (std::find(haystack.begin(), haystack.end(), needle) != haystack.end())
{
// We found the item in the list, so let's just continue
}
else
{
// not found
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句