// 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
#include <iostream>
using namespace std;
int main() {
string str1 = "mango";
string str2 = "apple";
int comparison = str1.compare(str2);
if (comparison == 0) {
cout << "Strings are equal." << endl;
} else if (comparison > 0) {
cout << "First string is greater than the second." << endl;
} else {
cout << "First string is less than the second." << endl;
}
}
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
char key[] = "Softhunt.net";
char buffer[50];
do {
cout<<"Which is your favourite tutorial website? ";
cin>>buffer;
} while (strcmp (key,buffer) != 0);
cout<<"Answer is correct!!"<<endl;
return 0;
}
//three methods to compare strings in c++
String strcmp() fucntion
In-built compare() function
c++ relational operators ('==','!=')