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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短