std::basic_string_view<CharT,Traits>:: size, std::basic_string_view<CharT,Traits>:: length
From cppreference.net
<
cpp
|
string
|
basic string view
|
constexpr
size_type size
(
)
const
noexcept
;
|
(C++17부터) | |
|
constexpr
size_type length
(
)
const
noexcept
;
|
(C++17부터) | |
뷰에 있는
CharT
요소의 개수를 반환합니다. 즉,
std::
distance
(
begin
(
)
, end
(
)
)
입니다.
목차 |
매개변수
(없음)
반환값
뷰에 있는
CharT
요소의 개수입니다.
복잡도
상수.
예제
이 코드 실행
#include <iostream> #include <string_view> // 작은따옴표로 둘러싼 문자열, 길이, // 빈 문자열인지 여부를 출력합니다. void check_string(std::string_view ref) { std::cout << std::boolalpha << "'" << ref << "' has " << ref.size() << " character(s); emptiness: " << ref.empty() << '\n'; } int main(int argc, char **argv) { // 빈 문자열 check_string(""); // 거의 항상 비어 있지 않음: argv[0] if (argc > 0) check_string(argv[0]); }
가능한 출력:
'' has 0 character(s); emptiness: true './a.out' has 7 character(s); emptiness: false
참고 항목
|
뷰가 비어 있는지 확인합니다
(public member function) |
|
|
최대 문자 수를 반환합니다
(public member function) |
|
|
문자 수를 반환합니다
(public member function of
std::basic_string<CharT,Traits,Allocator>
)
|