我想在数组的所有索引中添加一个整数.不使用循环.in single ststement.
int a [4] = {4,4,4,4}; 我想在所有索引中添加1 ..所以输出是cout <
输出:_ 5 5 5 5
我相信所有人......
#include <functional>
#include <algorithm>
int main()
{
int a[] = {1, 2, 3, 4};
std::transform(a, a + sizeof(a) / sizeof(a[0]), a, std::bind1st(std::plus<int>(), 1));
}
Run Code Online (Sandbox Code Playgroud)