The C++ char_traits class member, eq() program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Using C++ char_traits class member, eq() to test whether two char_type characters are equal
To show: How to use the eq() function, char_traits class member to test whether two char_type characters are equal in C++ programming
// the C++ char_traits class member, eq()
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
char_traits<char>::char_type chr1 = 'P';
char_traits<char>::char_type chr2 = 'Q';
char_traits<char>::char_type chr3 = 'P';
// testing for equality
bool Var1 = char_traits<char>::eq(chr1, chr2);
cout<<"Operation: eq(chr1, chr2)"<<endl;
if(Var1)
cout<<"The character chr1 and chr2 is equal."<<endl;
else
cout<<"The character chr1 and chr2 is not equal."<<endl;
// alternatively...
cout<<"\nOperation: using \'==\' operator, chr1==chr3"<<endl;
if(chr1 == chr3)
cout<<"The character chr1 and chr3 is equal."<<endl;
else
cout<<"The character chr1 and chr3 is not equal."<<endl;
return 0;
}
Output example:
Operation: eq(chr1, chr2)
The character chr1 and chr2 is not equal.
Operation: using '==' operator, chr1==chr3
The character chr1 and chr3 is equal.
Press any key to continue . . .