Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

string comparison c++

#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;
    }
}
Source by www.tutorialkart.com #
 
PREVIOUS NEXT
Tagged: #string #comparison
ADD COMMENT
Topic
Name
2+7 =