if (!vect_id.empty()){
size_t found;
for (size_t a = 0; a < vect_aux.size(); a++){
for(size_t r = 0; r < vect_id.size(); r++){
found=vect_id[r].find_first_of(vect_aux[a*2]);
if (found!=string::npos){
comp = comp + 1;
EV << "comp: " << comp << '\n';}
}
}
}
I also tried like this:
1 2 3 4 5 6 7 8 9 10
if (!vect_id.empty()){
for (size_t a = 0; a < vect_aux.size(); a++){
for(size_t r = 0; r < vect_id.size(); r++){
if (vect_id[r].compare(vect_auxi[a*2]) == 0){
comp = comp + 1;
EV << "comp: " << comp << '\n';}
}
}
}
I do not have an compilation error but the program when running close always here. The problem is in both cases the compare of the content of this string vectors.
for (size_t a = 0; a < vect_aux.size(); a++){
for(size_t r = 0; r < vect_id.size(); r++){
if (vect_id[r].compare(vect_aux[a*2]) == 0){}
when 'a' become > vect_aux.size() / 2 - you go out of range of (vect_aux[a*2]
for example (vect_aux have 4 elements) when 'a' become 3 -> vect_aux[a*2] == vect_aux[6] is wrong
try to understand next code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
std::vector< std::string > a; // you first vector ["asd","sdf"]
a.push_back( "asd" );
a.push_back( "sdf" );
std::vector< std::string > b; // you second vector ["sdf","asd"]
b.push_back( "sdf" );
b.push_back( "asd" );
std::vector< std::string > c; // additional vector ["sdf","asd"]
c.push_back( "sdf" );
c.push_back( "asd" );
std::cout << (a == c) << std::endl; // print "0" ( ["asd","sdf"] != ["sdf","asd"] )
std::cout << (b == c) << std::endl; // print "1" ( ["sdf","asd"] == ["sdf","asd"] )
std::set< std::string > a_s;
std::set< std::string > b_s;
std::copy( a.begin(), a.end(), std::insert_iterator< std::set< std::string > >( a_s, a_s.begin() ) ); // copy 'a' elements to set
std::copy( b.begin(), b.end(), std::insert_iterator< std::set< std::string > >( b_s, b_s.begin() ) ); // copy 'b' elements to set
std::cout << (a_s == b_s) << std::endl; // print "1"; now a_set == b_set