Compare strings : string compare « String « C++






Compare strings

  
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
  string myString = "hello";

  myString += ", there";

  string str2 = myString;

  if (myString == str2) {
    str2[0] = 'H';
  }

  cout << myString << endl;
  cout << str2 << endl;
}
  
    
  








Related examples in the same category

1.String: equals
2.string overloaded equality and relational operators
3.Compare string ignoring the case
4.Compare sub string: string4.compare( 0, string2.length(), string2 )
5.Use == > and < to compare strings
6.Use string.compare to compare two strings
7.Compare strings by index: string1.compare( 2, 5, string3, 0, 5)
8.Set with functor for string comparison
9.return true if c1 < c2 (ignoring case), false otherwise
10.Use std::lexicographical_compare to compare two char arrays
11.return true if c1 equals c2 (regardless of case), false otherwise