std::vector::size
Da cppreference.com
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
size_type size()const; | ||
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Índice |
[editar]Parâmetros
(Nenhum)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar]Valor de retorno
o número de elementos no recipiente
Original:
the number of elements in the container
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar]Exceções
[editar]Complexidade
Constant
[editar]Exemplo
The following code uses size
to display the number of elements in a 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";}
Saída:
nums contains 4 elements.
[editar]Veja também
retorna o número de elementos que podem ser mantidos em armazenamento atualmente alocado Original: returns the number of elements that can be held in currently allocated storage The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
verifica se o recipiente estiver vazio Original: checks whether the container is empty The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
retorna o número máximo possível de elementos Original: returns the maximum possible number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
changes the number of elements stored (função pública membro) |