[#bsl-basic_string-0fb-compare-0bc]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-0fb.adoc[basic&lowbar;string&lt;char&gt;]::compare
:relfileprefix: ../../
:mrdocs:

Lexicographically compare the substring of this string of the specified `numChars` length starting at the specified `position` (or the suffix of this string starting at `position` if `position &plus; numChars &gt; length()`) with the specified `other`, and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; See &lcub;Lexicographical Comparisons&rcub;&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()`&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;string&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
compare(
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other) const;
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
