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
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短