C++ 比较c+中的两个向量+;使用模板类

C++ 比较c+中的两个向量+;使用模板类,c++,class,templates,vector,memcpy,C++,Class,Templates,Vector,Memcpy,我想用模板类比较两个向量 vector<Msg> gExpMsg; vector<Msg> gRevcMsg; 向量gExpMsg; 载体grevcmg; 我必须使用模板类并使用memcmp比较2vector。 你能用C++代码指导我吗?< /P> 提前感谢。您可以使用STL相等或不匹配算法来比较两个容器。在这些算法中,如果需要,您可以给出自己的谓词函子。下面是您可以找到示例代码的链接 失配返回包含两个容器之间差异的对值(在本例中为向量) 下面是一些用于快速查看的示

我想用模板类比较两个向量

vector<Msg> gExpMsg;
vector<Msg> gRevcMsg;
向量gExpMsg; 载体grevcmg; 我必须使用
模板类并使用
memcmp
比较2
vector
。 你能用C++代码指导我吗?< /P>
提前感谢。

您可以使用STL相等或不匹配算法来比较两个容器。在这些算法中,如果需要,您可以给出自己的谓词函子。下面是您可以找到示例代码的链接

失配返回包含两个容器之间差异的对值(在本例中为向量) 下面是一些用于快速查看的示例片段

//find first mismatch
pair<vector<int>::iterator,list<int>::iterator> values;
values = mismatch (coll1.begin(), coll1.end(), //first range
                      coll2.begin());    //second range
if (values.first == coll1.end()) 
  cout <<"no mismatch"<<endl;     
else
  cout <<"first mismatch: "<<*values.first<<" and "<<*values.second<<endl;
//查找第一个不匹配项
配对值;
值=不匹配(coll1.begin(),coll1.end(),//第一个范围
coll2.begin())//第二范围
if(values.first==coll1.end())

你能把你目前掌握的密码发出去吗?顺便说一句,
memcpy()
copies,它不进行比较。抱歉。。不是记忆。。。memcmptemplate Msg Validate(Msg m1,Msg m2){memcmp();//我必须为m1和m2做些什么}
values = mismatch (coll1.begin(), coll1.end(), //first range
                       col12. begin(),   //second range
                       less_equal<int>() )  //criterion
if (values.first == coll1.end()) 
  cout <<"always less-or-equal"<<endl;
else 
  cout <<"not less-or-equal: "<<*values.first<<" and "          
                            <<*values.second<<endl;