Namespaces
Variants

std::array<T,N>:: size

From cppreference.net

constexpr size_type size ( ) const noexcept ;
(C++11 이후)

컨테이너의 요소 개수를 반환합니다.

목차

반환값

std:: distance ( begin ( ) , end ( ) )

복잡도

상수.

예제

다음 코드는 size 를 사용하여 std::array 내 요소의 개수를 표시합니다:

#include <array>
#include <iostream>
int main()
{ 
    std::array<int, 4> nums{1, 3, 5, 7};
    std::cout << "nums contains " << nums.size() << " elements.\n";
}

출력:

nums contains 4 elements.

참고 항목

컨테이너가 비어 있는지 확인합니다
(public member function)
가능한 최대 요소 개수를 반환합니다
(public member function)
(C++17) (C++20)
컨테이너나 배열의 크기를 반환합니다
(function template)