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 이 가리키는 첫 번째 요소부터 시작하여 첫 번째 널 문자 직전까지의 문자 배열 내 문자 개수를 반환합니다. str 이 가리키는 문자 배열에 널 문자가 존재하지 않을 경우 동작은 정의되지 않습니다.
목차 |
매개변수
| str | - | 검사할 null로 종료되는 바이트 문자열을 가리키는 포인터 |
반환값
널 종료 문자열 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
|
|