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
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便