Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ string comparison

// C++ program to check if
// two strings are identical
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    char string1[100], string2[100];
  
    // Get the strings which
    // is to be checked
    cin >> string1;
    cout << "Enter the first string: " << string1;
  
    // Get the strings which
    // is to be checked
    cin >> string2;
    cout << "
Enter the second string: " << string2;
  
    // Check if both strings are equal
    cout << "
Are both strings same: ";
  
    if (strcmp(string1, string2) == 0)
    {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
  
    return 0;
}
  
// This code is contributed by Akanksha Rai
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #string #comparison
ADD COMMENT
Topic
Name
3+2 =