valarray::size
Recherche le nombre d'éléments dans un valarray.
size_t size( ) const;
Valeur de retour
Le nombre d'éléments dans le valarray opérande.
Exemple
Lors de la compilation cet exemple avec l'indicateur d' /Wp64 ou sur une plateforme 64 bits, l'avertissement du compilateur l'erreur C4267 est généré.Pour plus d'informations sur cet avertissement, consultez Avertissement du compilateur (niveau 3) C4267.
// valarray_size.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main()
{
using namespace std;
int i;
size_t size1, size2;
valarray<int> va1(10), va2(12);
for (i = 0; i < 10; i += 1)
va1[i] = i;
for (i = 0; i < 10; i += 1)
va2[i] = i;
cout << "The operand valarray va1(10) is: ( ";
for (i = 0; i < 10; i++)
cout << va1[i] << " ";
cout << ")." << endl;
size1 = va1.size();
cout << "The number of elements in the valarray va1 is: va1.size = "
<< size1 << "." <<endl << endl;
cout << "The operand valarray va2(12) is: ( ";
for (i = 0; i < 10; i++)
cout << va2[i] << " ";
cout << ")." << endl;
size2 = va2.size();
cout << "The number of elements in the valarray va2 is: va2.size = "
<< size2 << "." << endl << endl;
// Initializing two more elements to va2
va2[10] = 10;
va2[11] = 11;
cout << "After initializing two more elements,\n "
<< "the operand valarray va2(12) is now: ( ";
for (i = 0; i < 12; i++)
cout << va2[i] << " ";
cout << ")." << endl;
cout << "The number of elements in the valarray va2 is still: "
<< size2 << "." << endl;
}
Configuration requise
en-tête : <valarray>
l'espace de noms : DST