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