How to compare two strings in C++ -


this question has answer here:

lets have string , string b know have use a.equals(b) compare 2 strings in c++, looks can directly use if(a==b)..., , found string has compare() fuction, 1 should use, == or compare()

use == when want test equality. call str1.operator ==(str2)

use std::string::compare if want know whether string less than, equal or greater other string. std::string::compare returns negative number (if str1 lexicographycally or in dictionary order less str2), 0 or positive number accordingly. (analogous str1 - str2)


Comments