string::Compare

Description

Perform a case-sensitive comparison of this string object with another string.

Syntax

int Compare( LPCSTR lpsz )

Parameters

lpsz
[input] The other string used for comparison.

Return

Zero if the strings are identical, < 0 if this string object is less than lpsz, or > 0 if this string object is greater than lpsz.

Examples

EX1

void string_Compare_ex1()
{
    string str("abc");
    int nRet;
 
    nRet = str.Compare("abb"); 
    out_int("This string is greater than \"abb\" : 1", nRet);   // 1
 
    nRet = str.Compare("abc");
    out_int("The strings are identical : ", nRet);                // 0
 
    nRet = str.Compare("abz");
    out_int("This string is less than \"abz\" : ", nRet);       // -1
 
    nRet = str.Compare("ABC");
    out_int("This string is greater than \"ABC\" : ", nRet);    // 1
 
    nRet = str.Compare("ab");
    out_int("This string is greater than \"ab\" : ", nRet);     // 1
 
    nRet = str.Compare("abcd");
    out_int("This string is less than \"abcd\" : ", nRet);      // -1
}

Remark

See Also

string::CompareNoCase

header to Include

origin.h