1: Use "" ","! Comparison operators such as = "," >= "can compare the contents of two strings. The comparison method is to compare each character from the beginning of the two string string, until there is an inconsistency between the two. Compare the literal values of these two different characters and draw the corresponding result. The code is as follows:
//6.21.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<iostream>#include<string>using namespacestd;intMainintARGC, _tchar*argv[]) { stringS1; stringS2; cout<<"Please enter a two string"<<Endl; CIN>>S1; CIN>>S2; if(S1 = =S2) {cout<<"Two strings equal"<<Endl; } Else if(s1>S2) {cout<<"The first character is greater than the second string"<<Endl; } Else{cout<<"The second character is greater than the second string"<<Endl; } return 0;}View Code
Operation Result:
Getting Started with C + + Classic-Example 6.21-comparing string strings, comparing two strings