C ++ STL中的求反函数
求反函数用于对给定值求反,从而更改值的符号。它将负值更改为正值,反之亦然。
函数原型:
function transform(a_begin, a_end, a1_begin, negate()): a_begin = 数组的下界。 a_end = 数组的上界。 a1_end = 第二个修改数组的下界。 negate() = 对数组的值求反。
范例程式码
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int main() {
int a[] = { 4,6,7, -10, -20, -30 };
transform(a, a + 6, a, negate<int>());
for (int i = 0; i < 6; i++)
cout << a[i] << ' ';
return 0;
}输出结果
-4 -6 -7 10 20 30
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短