valarray::size
查看項目的數目。valarray 的。
size_t size( ) const;
傳回值
項目的數目。valarray 運算元的。
範例
當編譯這個範例使用 /Wp64 旗標或在 64 位元平台時,警告的編譯器 C4267 產生。 如需這項警告的詳細資訊,請參閱 編譯器警告 (層級 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;
}
需求
標題: <valarray>
命名空間: std