若要檢視英文版的文章，請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上，即可在快顯視窗顯示英文原文。 譯文 原文

# valarray::operator+=

Visual Studio 2015

## 語法

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

_Right

## 傳回值

```// 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 最初是:(2 -1 2 -1 2 -1 2 -1)。
valarray 初始 _Right 如下:(0 1 2 3 4 5 6 7)。

valarray:(2 0 4 2 6 4 8 6)。```