_fileNameBuffer and _filePathBuffer are string-vectors declared as you can see above, and the other 2 strings are just simple strings.
The problem is that even if the strings are the same it's not working, so it's not going through the if statement, I think is the length of the strings file_to_find and _fileNameBuffer.at(i), because they can have more than 50 chars, and maybe the function "compare" has some kind of limit.
With this information do you know what could be the problem.
make a for loop and compare one char at a time.
when they are not equal, print the individual characters in hex and the index.
should show you what is different.
Ive compared GB sized buffers representing large xml files. The tools work fine. Its not related to the length. Its really easy to have a small unseen difference though, which is why we let the computer do the dirty work of figuring out where that is.
#include <iostream>
#include <string>
#include <algorithm>
// silently return true if a == b. if not, print out
// information about the mismatch and return false
bool debug_expected_equal( const std::string& a, const std::string& b )
{
if( a.size() != b.size() )
{
// mismatched string lengths: print out the string sizes
std::cout << "size mismatch: " << a.size() << " and " << b.size() << '\n' ;
returnfalse ;
}
// http://en.cppreference.com/w/cpp/algorithm/mismatchconstauto pair = std::mismatch( a.begin(), a.end(), b.begin() ) ;
if( pair.first == a.end() ) returntrue ; // a and b compare equal
// mismatched strings: print out mismatched position and characters
std::cout << "mismatch at pos " << pair.first - a.begin()
<< " chars: '" << *pair.first << "' (" << int(*pair.first) << ')'
<< " and '" << *pair.second << "' (" << int(*pair.second) << ")\n" ;
returnfalse ;
}
int main()
{
const std::string a = "The problem is that even if the strings are the same it's not ""working, so it's not going through the if statement, I think is ""the length of the strings file_to_find and _fileNameBuffer.at(i), ""because they can have more than 50 chars, and maybe the function ""\"compare\" has some kind of limit." ;
std::string b = a ;
std::cout << std::boolalpha << debug_expected_equal(a,b) << "\n\n" ; // true
b += '!' ;
std::cout << debug_expected_equal(a,b) << "\n\n" ; // size mismatch: 290 and 291
// false
b.pop_back() ;
b[217] = 'Z' ;
std::cout << debug_expected_equal(a,b) << '\n' ; // mismatch at pos 217 chars: 'e' (101) and 'Z' (90)
// false
}