operator- (<valarray>)
获取两个具有相同的大小的 valarrays 的对应元素的元素不同或之间 valarray 之间一个值。
template<class Type>
valarray<Type> operator-(
const valarray<Type>& _Left,
const valarray<Type>& _Right
);
template<class Type>
valarray<Type> operator-(
const valarray<Type>& _Left,
const Type& _Right
);
template<class Type>
valarray<Type> operator-(
const Type& _Left,
const valarray<Type>& _Right
);
参数
_Left
值或 valarray 该值或 valarrays 减去。将用作其他窗体不同的含义。_Right
值或 valarray 用作该是从其他值或 valarrays 减去减数以窗体的差异。
返回值
元素为 _Left 元素和 _Right.valarray 的差异
备注
描述用于减法的算术术语:
差异 - = 被减数减数
示例
// valarray_op_ediff.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 8 ), vaR ( 8 );
valarray<int> vaNE ( 8 );
for ( i = 0 ; i < 8 ; i += 2 )
vaL [ i ] = 10;
for ( i = 1 ; i < 8 ; i += 2 )
vaL [ i ] = 0;
for ( i = 0 ; i < 8 ; i++ )
vaR [ i ] = i;
cout << "The initial Left 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;
vaNE = ( vaL - vaR );
cout << "The element-by-element result of "
<< "the difference is the\n valarray: ( ";
for (i = 0 ; i < 8 ; i++ )
cout << vaNE [ i ] << " ";
cout << ")." << endl;
}
要求
Header: <valarray>
命名空间: std