valarray::operator+
应用于加号于valarray的每个元素的一元运算符。
valarray<Type> operator+( ) const;
返回值
元素是以及这些操作数数组的valarray。
示例
// valarray_op_eplus.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 10 );
valarray<int> vaPLUS ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
vaL [ i ] = -i;
for ( i = 1 ; i < 10 ; i += 2 )
vaL [ i ] = i-1;
cout << "The initial valarray is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
vaPLUS = +vaL;
cout << "The element-by-element result of "
<< "the operator+ is the\n valarray: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaPLUS [ i ] << " ";
cout << ")." << endl;
}
要求
标头: <valarray>
命名空间: std