O'Reilly logo

C++11 for Programmers, Second Edition by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 << ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required