19.3. Comparing strings

Class string provides member functions for comparing strings. Figure 19.2 demonstrates class string’s comparison capabilities.

 1   // Fig. 19.2: Fig19_02.cpp 2   // Comparing strings. 3   #include <iostream> 4   #include <string> 5   using namespace std; 6  7   int main() 8   { 9      string string1( "Testing the comparison functions." );10      string string2( "Hello" );11      string string3( "stinger" );12      string string4( string2 ); // "Hello"13 14      cout << "string1: " << string1 << "\nstring2: " << string215         << "\nstring3: " << string3 << "\nstring4: " << string4 << "\n\n";16 17      // comparing string1 and string418      if ( string1 == string4 )19         cout << ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.