Greetings,
I'm currently facing a problem on how to compare 2 vector's elements. For example, assuming we have declared 2 integer type vectors:
vector <int> v1;
vector <int> v2;
and both vectors have some integer values stored inside. What is the syntax that I can use to check such that all the elements in v1 and v2 are the same? Can I do the following? Do I need to declare something to overload the == operator? If yes, can tell me how please?
if(v1 == v2)
{ }
-----------------------------------------------------------------------------------
Second Question..
If the above syntax can be used, then I have the following problem which requires some suggestion. It's cracking my head right now..
Let's say if there are similar elements found between these 2 vectors. Once the similar element is found, I want to remove that particular element from v1 and the problem that I faced is shown by "????". Since I do not know which element will be found as similar, so what am I suppose to fill into that "????"
for(int i=0; i < v1.size() ; i++)
{
if(v1 == v2)
{
v1.erase(v1.beg in() + ????);
}
}
I really want to understand this and any advice would be much appreciated.
I'm currently facing a problem on how to compare 2 vector's elements. For example, assuming we have declared 2 integer type vectors:
vector <int> v1;
vector <int> v2;
and both vectors have some integer values stored inside. What is the syntax that I can use to check such that all the elements in v1 and v2 are the same? Can I do the following? Do I need to declare something to overload the == operator? If yes, can tell me how please?
if(v1 == v2)
{ }
-----------------------------------------------------------------------------------
Second Question..
If the above syntax can be used, then I have the following problem which requires some suggestion. It's cracking my head right now..
Let's say if there are similar elements found between these 2 vectors. Once the similar element is found, I want to remove that particular element from v1 and the problem that I faced is shown by "????". Since I do not know which element will be found as similar, so what am I suppose to fill into that "????"
for(int i=0; i < v1.size() ; i++)
{
if(v1 == v2)
{
v1.erase(v1.beg in() + ????);
}
}
I really want to understand this and any advice would be much appreciated.
Comment