Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
Functions | ||||||||||||||||||||||||||||||||||||
Character classification | ||||||||||||||||||||||||||||||||||||
Character manipulation | ||||||||||||||||||||||||||||||||||||
Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||
String manipulation | ||||||||||||||||||||||||||||||||||||
String examination | ||||||||||||||||||||||||||||||||||||
Character array functions | ||||||||||||||||||||||||||||||||||||
Miscellaneous | ||||||||||||||||||||||||||||||||||||
Defined in header <cstring> | ||
int strcmp(constchar* lhs,constchar* rhs); | ||
Compares two null-terminated byte strings lexicographically.
The sign of the result is the sign of the difference between the values of the first pair of characters (both interpreted asunsignedchar) that differ in the strings being compared.
The behavior is undefined iflhs orrhs are not pointers to null-terminated strings.
Contents |
lhs, rhs | - | pointers to the null-terminated byte strings to compare |
Negative value iflhs appears beforerhs in lexicographical order.
Zero iflhs andrhs compare equal.
Positive value iflhs appears afterrhs in lexicographical order.
#include <algorithm>#include <cstring>#include <iostream>#include <vector> int main(){std::vector<constchar*> cats{"Heathcliff","Snagglepuss","Hobbes","Garfield"};std::sort(cats.begin(), cats.end(),[](constchar* strA,constchar* strB){return std::strcmp(strA, strB)<0;}); for(constchar* cat: cats)std::cout<< cat<<'\n';}
Output:
GarfieldHeathcliffHobbesSnagglepuss
compares a certain number of characters from two strings (function)[edit] | |
compares two wide strings (function)[edit] | |
compares two buffers (function)[edit] | |
compares two strings in accordance to the current locale (function)[edit] | |
C documentation forstrcmp |