bool CompareFiles(const std::string& filename1, const std::string& filename2) { std::ifstream file1(filename1); std::ifstream file2(filename2); std::istreambuf_iterator<char> begin1(file1); std::istreambuf_iterator<char> begin2(file2); std::istreambuf_iterator<char> end; return range_equal(begin1, end, begin2, end); }
bool equal_streams(std::istream& s1, std::istream& s2) { typedef std::istreambuf_iterator<char, std::char_traits<char> > iterator; iterator begin1(s1.rdbuf()); iterator begin2(s2.rdbuf()); iterator end; for(; begin1 != end && begin2 != end; ++begin1, ++begin2) if(*begin1 != *begin2) return false; return begin1 == end && begin2 == end; }
bool endsWith(const string& str1, const string& str2) { if (str1.length() < str2.length()) { return false; } string::const_iterator it1(str1.end()); string::const_iterator begin1(str1.begin()); string::const_iterator it2(str2.end()); string::const_iterator begin2(str2.begin()); while (it1 != begin1 && it2 != begin2) { if (*it1 != *it2) { return false; } --it1; --it2; } return true; }