名前空間
変種
操作

std::vector<T,Allocator>::size

提供: cppreference.com
< cpp‎ | container‎ | vector
 
 
 
 
size_type size() const;
(C++11未満)
size_type size() const noexcept;
(C++11以上)

コンテナ内の要素の数、すなわち std::distance(begin(), end()) を返します。

目次

[編集] 引数

(なし)

[編集] 戻り値

コンテナ内の要素の数。

[編集] 計算量

一定。

[編集]

以下のコードは size を使用して std::vector<int> の要素数を表示します。

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

出力:

nums contains 4 elements.

[編集] 関連項目

現在確保されて��る記憶域に保持できる要素の数を返します
(パブリックメンバ関数) [edit]
コンテナが空かどうか調べます
(パブリックメンバ関数) [edit]
可能な最大の要素数を返します
(パブリックメンバ関数) [edit]
格納されている要素の数を変更します
(パブリックメンバ関数) [edit]