std::char_traits::compare - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::char_traits::compare

From cppreference.com
< cpp‎ | string‎ | char traits

static int compare( const char_type* s1, const char_type* s2, std::size_t count ); |  | (until C++17)
static constexpr int compare( const char_type* s1, const char_type* s2, std::size_t count ); |  | (since C++17)

Compares the first `count` characters of the character strings `s1` and `s2`. The comparison is done lexicographically.

If `count` is zero, strings are considered equal.

### [edit] Parameters

s1, s2 | - | pointers to character strings to compare
count | - | the number of characters to compare from each character string

### [edit] Return value

Negative value if `s1` is less than `s2`.

​0​ if `s1` is equal to `s2`.

Positive value if `s1` is greater than `s2`.

### [edit] Exceptions

(none)

### [edit] Complexity

Linear in `count`.

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string/char_traits/compare&oldid=88212"