C++ boost::algorithm::string::equals()

C++ boost::algorithm::string::equals()


     This function is included in the "boost/algorithm/string" library. This library contains some brilliant methods which  help in accomplishing string manipulations that are lacking in STL library. 

This function is used to check whether the given two strings are equal or not. i.e., checks character by character for equality.

header file:





    input : an input string(sequence)

    test : a test string(sequence)

(along with the above parameters an additional optional parameter can be passed which specifies the predicate for comparision. i.e., the user may specify his own new function for comparision.

The given function is case sensitive, i.e., it does the check case-sensitively. For example, "I am not well" is not same as "i am not WELL"

 There is another variation present i.e., iequals() , which takes the same parameters as input, but instead of doing a case-sensitive test, it ignores the case of the characters and does the check, i.e., it does the check case-insensitively. For example, "I am not well" is same as "i am not WELL".


#include<iostream> #include<boost/algorithm/string.hpp> using namespace std; using namespace boost::algorithm; int main() { //Input strings string str[] = {"Welcome","You are using boost","its very interestING ","It is very effective"}; //Test strings string test[] = {"Welcome","You areusing boost","its very interestING ","IT IS VERY EFFECTIVE"}; //performing the checks and printing the results with equals cout<<"Using equals()"<<endl<<endl; for(int i=0;i<4;i++) { cout<<str[i]<<" is checked with "<<test[i]<<endl; cout<<"Result : The string equals test- "<<equals(str[i],test[i])<<endl<<endl; } //performing the checks and printing the results with iequals cout<<"Using iequals()"<<endl<<endl; cout<<str[3]<<" is checked with "<<test[3]<<endl; cout<<"Result : The string equals test- "<<iequals(str[3],test[3])<<endl; }



In the above output, 1 means TRUE and 0 means FALSE.

As we can observe for str1 and str3 equals() returns TRUE and for str2 and str4 it returns FALSE as the test string is not equal to the input strings.(equals() performs case-sensitve check).

On the contrary, iequals() return TRUE for str4 as it does case insensitive check.

More Articles of Md Safi Ur Rahman Khan:

Name Views Likes
C++ boost::algorithm::string::join() 577 0
C++ boost::algorithm::string::split() 607 0
C++ boost::algorithm::string::find_all() 647 0
C++ boost::algorithm::string::erase_tail() 249 0
C++ boost::algorithm::string::replace_tail() 212 0
C++ boost::algorithm::string::erase_head() 277 0
C++ boost::algorithm::string::replace_head() 210 0
C++ boost::algorithm::string::erase_all() 898 1
C++ boost::algorithm::replace_all() 2050 0
C++ boost::algorithm::string::erase_nth() 216 0
C++ boost::algorithm::string::replace_nth() 222 0
C++ boost::algorithm::string::replace_last() 247 0
C++ boost::algorithm::string::erase_last() 244 0
C++ boost::algorithm::string::erase_first() 216 1
C++ boost::algorithm::string::replace_first() 433 0
C++ boost::algorithm::string::find_token() 352 0
C++ boost::algorithm::string::find_tail() 201 1
C++ boost::algorithm::string::find_head() 213 0
C++ boost::algorithm::string::find_last() 301 1
C++ boost::algorithm::string::find_first() 750 1
C++ boost::algorithm::string::all() 225 1
C++ boost::algorithm::string::lexicographical_compare() 215 0
C++ boost::algorithm::string::equals() 379 0
C++ boost::algorithm::string::contains() 1826 0
C++ boost::algorithm::string::ends_with() 1283 0
C++ boost::algorithm::string::starts_with() 2060 0
C++ boost::algorithm::string::trim_if() 713 1
C++ boost::algorithm::string::trim() 3797 0
C++ boost::algorithm::string::trim_right_if() 523 1
C++ boost::algorithm::string::trim_left_if() 385 1
C++ boost::algorithm::string::trim_right() 282 3
C++ boost::algorithm::string::trim_left() 364 1
C++ boost::algorithm::string::to_lower() 737 1
C++ boost::algorithm::string::to_upper() 298 1
C++ Program to Implement Dequeue 1327 5
C++ Program to Implement Dequeue 241 3