- cstring[meta header]
- std[meta namespace]
- function[meta id-type]
namespace std {
int strcmp(const char* s1, const char* s2);
}文字列を比較する。
s1が指す文字列とs2が指す文字列を比較する。各文字はunsigned charとして比較される。
2つの文字列で最初に異なる文字について、s1側の文字がs2側の文字より大きい場合は正の整数、小さい場合は負の整数を返す。2つの文字列が等しい場合は0を返す。
- この関数は、フリースタンディング処理系でも使用できる。
#include <cstring>
#include <iostream>
int main()
{
std::cout << std::boolalpha;
std::cout << (std::strcmp("abc", "abc") == 0) << std::endl;
std::cout << (std::strcmp("abc", "abd") < 0) << std::endl;
}- std::strcmp[color ff0000]
true
true
- C++98
- P2338R4 Freestanding Library: Character primitives and the C library
- C++26で、この関数がフリースタンディング処理系で使用可能になった