CStringT::Compare

Compares two strings (case sensitive).

int Compare(
   PCXSTR psz
) const;

Parameters

  • psz
    The other string used for comparison.

Return Value

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

Remarks

The generic-text function _tcscmp, which is defined in TCHAR.H, maps to either strcmp, wcscmp, or _mbscmp, depending on the character set that is defined at compile time. Each function performs a case-sensitive comparison of the strings and is not affected by locale. For more information, see strcmp, wcscmp, _mbscmp.

If the string contains embedded nulls, for purposes of comparison the string is considered to be truncated at the first embedded null character.

Example

The following example demonstrates the use of CStringT::Compare.

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString s1(_T("abc"));
CAtlString s2(_T("abd"));
ASSERT(s1.Compare(s2) < 0);    // Compare with another CAtlString.
ASSERT(s1.Compare(_T("abe")) < 0); // Compare with LPTSTR string.   

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class

Other Resources

CStringT Members