This C++ Program demonstrates implementation of LexicoGraphical_Compare in STL.
Here is source code of the C++ Program to demonstrate LexicoGraphical_Compare in STL. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Implement LexicoGraphical_Compare in Stl
*/
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;
bool mycomp (char c1, char c2)
{
return tolower(c1) < tolower(c2);
}
int main ()
{
int flen, blen;
char foo[] = "Apple";
char bar[] = "apartment";
flen = strlen(foo);
blen = strlen(bar);
cout << boolalpha;
cout << "Comparing foo and bar lexicographically (foo < bar): "<<endl;
cout << "Using default comparison (operator <): ";
cout << lexicographical_compare(foo, foo + flen, bar, bar + blen);
cout <<endl;
cout << "Using mycomp as comparison object: ";
cout << lexicographical_compare(foo, foo + flen, bar, bar + blen, mycomp);
cout <<endl;
return 0;
}
$ g++ LexicoGraphical_Compare.cpp $ a.out Comparing foo and bar lexicographically (foo < bar): Using default comparison (operator <): true Using mycomp as comparison object: false ------------------ (program exited with code: 0) Press return to continue
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Check Programming Books
- Check Computer Science Books
- Practice Design & Analysis of Algorithms MCQ
- Practice Programming MCQs
- Check Data Structure Books