std:: strlen
From cppreference.net
C++
Text processing library
| 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 | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Null-terminated byte strings
| Functions | ||||||||||||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||||||||||||
| Character array functions | ||||||||||||||||||||||||||||||||||||
| Miscellaneous | ||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<cstring>
|
||
|
std::
size_t
strlen
(
const
char
*
str
)
;
|
||
指定されたバイト文字列の長さ、すなわち str が指す文字配列の先頭要素から、最初のnull文字を含まないまでの文字数を返します。 str が指す文字配列にnull文字が存在しない場合、動作は未定義です。
目次 |
パラメータ
| str | - | 検査対象のヌル終端バイト文字列へのポインタ |
戻り値
ヌル終端文字列 str の長さ。
実装例
std::size_t strlen(const char* start) { // 注意: startはnullptrチェックされていません! const char* end = start; while (*end != '\0') ++end; return end - start; } |
例
このコードを実行
#include <cstring> #include <iostream> int main() { const char str[] = "dog cat\0mouse"; std::cout << "without null character: " << std::strlen(str) << '\n' << "with null character: " << sizeof str << '\n'; }
出力:
without null character: 7 with null character: 14
関連項目
|
ワイド文字列の長さを返す
(関数) |
|
|
次のマルチバイト文字のバイト数を返す
(関数) |
|
|
Cドキュメント
for
strlen
|
|