#include <iostream> #include <string> using namespace std; intmain() { string a("aBcdef"); string b("AbcdEf"); string c("123456"); string d("123dfg"); //The following are various comparison methods //Subtract the following ASCII code from the front, >0 returns 1, <0 returns -1, the same returns 0 //Completely compare a and b int m=a.compare(b); //Comparison of "Bcdef" and "AbcdEf", comparing bits 1 to 5 of a and b int n=a.compare(1,5,b); //Comparison of "Bcdef" and "Ef" int p=a.compare(1,5,b,4,2); //Comparison of "123" and "123" int q=c.compare(0,3,d,0,3); cout<<"m="<<m<<",n="<<n<<",p="<<p<<",q="<<q<<endl; return 0; }
The compare function of the C++ STL string class uses
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325592033&siteId=291194637
Ranking