std::size_t - cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Definido no cabeçalho <cstddef> |
||
| Definido no cabeçalho <cstdio> |
||
| Definido no cabeçalho <cstring> |
||
| Definido no cabeçalho <ctime> |
||
|
|
||
std::size_t é do tipo unsigned inteira do resultado do operador
sizeofeo operador
alignof.
Original:
std::size_t is the unsigned integer type of the result of the
sizeofoperator and the
alignofoperator.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Notas
size_t pode armazenar o tamanho máximo de um objeto, teoricamente possível, de qualquer tipo (incluindo matriz). Em muitas plataformas (uma exceção são sistemas com endereçamento segmentado) std :: size_t pode armazenar o valor de qualquer ponteiro não-membro, caso em que é sinônimo de std::uintptr_t.
Original:
size_t can store the maximum size of a theoretically possible object of any type (including array). On many platforms (an exception are systems with segmented addressing) std::size_t can safely store the value of any non-member pointer, in which case it is synonymous with std::uintptr_t.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::size_t é comumente utilizado para indexação de matriz e contagem de loop. Programas que usam outros tipos, como unsigned int, para indexação de matriz pode falhar em, por exemplo, Sistemas de 64 bits em que o índice excede UINT_MAX ou se se baseia em 32 bits aritmética modular.
Original:
std::size_t is commonly used for array indexing and loop counting. Programs that use other types, such as unsigned int, for array indexing may fail on, e.g. 64-bit systems when the index exceeds UINT_MAX or if it relies on 32-bit modular arithmetic.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Quando a indexação C + +, tais como recipientes de std::string, std::vector, etc, do tipo apropriado é o membro size_type typedef fornecida por esses recipientes. Ele é geralmente definida como um sinônimo para std::size_t.
Original:
When indexing C++ containers, such as std::string, std::vector, etc, the appropriate type is the member typedef size_type provided by such containers. It is usually defined as a synonym for std::size_t.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#include <cstddef> int main() { const std::size_t N = 100; int* a = new int[N]; for(std::size_t n = 0; n<N; ++n) a[n] = n; delete[] a; }
Veja também
assinado tipo inteiro retornado quando subtraindo dois ponteiros Original: signed integer type returned when subtracting two pointers The text has been machine-translated via Google Translate. (typedef) [edit] | |
byte offset do início de um tipo padrão de disposição-membro especificado Original: byte offset from the beginning of a standard-layout type to specified member The text has been machine-translated via Google Translate. (função macro) [edit] | |