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