// string/iter2.cpp #include #include #include using namespace std; bool nocase_compare (char c1, char c2) { return toupper(c1) == toupper(c2); } int main() { string s1("This is a string"); string s2("STRING"); // Сравнение строк без учета регистра символов if (s1.size() == s2.size() && // Проверить совпадение размеров equal (s1.begin(),s1.end(), // Первая строка s2.begin(), // Вторая строка nocase_compare)) { // Критерий сравнения cout << "the strings are equal" << endl; } else { cout << "the strings are not equal" << endl; } // Поиск без учета регистра символов string::iterator pos; pos = search (s1.begin(),s1.end(), // Строка, в которой ведется поиск s2.begin(),s2.end(), // Искомая подстрока nocase_compare); // Критерий сравнения if (pos == s1.end()) { cout << "s2 is not a substring of s1" << endl; } else { cout << '"' << s2 << "\" is a substring of \"" << s1 << "\" (at index " << pos - s1.begin() << ")" << endl; } }