valarray::operator+=

添加元素的指定valarray或元素类型的值,元素,以valarray的操作数。

valarray<Type>& operator+=(
   const valarray<Type>& _Right
);
valarray<Type>& operator+=(
   const Type& _Right
);

参数

  • _Right
    元素类型的valarray或值与要添加valarray的操作数,元素,对valarray的操作数。

返回值

元素是valarray该操作数的元素求和与 _Right.的valarray

示例

// valarray_op_eadd.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>

int main( )
{
   using namespace std;
   int i;

   valarray<int> vaL ( 8 ), vaR ( 8 );
   for ( i = 0 ; i < 8 ; i += 2 )
      vaL [ i ] =  2;
   for ( i = 1 ; i < 8 ; i += 2 )
      vaL [ i ] =  -1;
   for ( i = 0 ; i < 8 ; i++ )
      vaR [ i ] =  i;
   
   cout << "The initial valarray is: ( ";
      for (i = 0 ; i < 8 ; i++ )
         cout << vaL [ i ] << " ";
   cout << ")." << endl;

   cout << "The initial _Right valarray is: ( ";
      for (i = 0 ; i < 8 ; i++ )
         cout << vaR [ i ] << " ";
   cout << ")." << endl;

   vaL += vaR;
   cout << "The element-by-element result of "
        << "the sum is the\n valarray: ( ";
      for (i = 0 ; i < 8 ; i++ )
         cout << vaL [ i ] << " ";
   cout << ")." << endl;
}
  
  
  

要求

标头: <valarray>

命名空间: std

请参见

参考

valarray Class