A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.cplusplus.com/vector::size below:

public member function

<vector>

std::vector::size
size_type size() const noexcept;

Return size

Returns the number of elements in the vector.

This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.



Parameters none

Return Value The number of elements in the container.

Member type size_type is an unsigned integral type.



Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// vector::size
#include <iostream>
#include <vector>

int main ()
{
  std::vector<int> myints;
  std::cout << "0. size: " << myints.size() << '\n';

  for (int i=0; i<10; i++) myints.push_back(i);
  std::cout << "1. size: " << myints.size() << '\n';

  myints.insert (myints.end(),10,100);
  std::cout << "2. size: " << myints.size() << '\n';

  myints.pop_back();
  std::cout << "3. size: " << myints.size() << '\n';

  return 0;
}

Output:
0. size: 0
1. size: 10
2. size: 20
3. size: 19


Complexity Constant.

Iterator validity No changes.

Data races The container is accessed.
No contained elements are accessed: concurrently accessing or modifying them is safe.

Exception safetyNo-throw guarantee: this member function never throws exceptions.

See also
vector::capacity
Return size of allocated storage capacity (public member function)
vector::resize
Change size (public member function)
vector::max_size
Return maximum size (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3