12345678
#include <string> #include <algorithm> bool tail_equals( const std::string& str, const std::string& expected_tail ) { return ( expected_tail.size() <= str.size() ) && std::equal( expected_tail.rbegin(), expected_tail.rend(), str.rbegin() ) ; }
substr()
12345
string f="seguir"; if((f.substr((f.length()-2),2))=="ir") { cout<<"extracted letters from "<<f<<": "<<f.substr((f.length()-2),2)<<endl; }
1234567891011121314151617
#include <string> #include <algorithm> #include <iostream> bool tail_equals( const std::string& str, const std::string& expected_tail ) { return ( expected_tail.size() <= str.size() ) && std::equal( expected_tail.rbegin(), expected_tail.rend(), str.rbegin() ) ; } int main() { const std::string word = "seguir" ; const std::string tail = "ir" ; if( tail_equals( word, tail ) ) std::cout << "something\n" ; if( tail_equals( "cout something", "thing" ) ) std::cout << "thing\n" ; }