How can I check whether the first "n" elements of two vectors are equal or not?
I tried the following:
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
typedef vector<double> v_t;
int main(){
v_t v1,v2;
int n = 9;
for (int i = 1; i<10; i++){
v1.push_back(i);
v2.push_back(i);
}
v1.push_back(11);
v2.push_back(12);
if (v1.begin()+n == v2.begin()+n)
cout << "success" << endl;
else
cout << "failure" << endl;
}
Why does it print "failure" and not "success"?
See Question&Answers more detail:os