想在整数数组的所有索引中添加一个整数

0 c++ arrays

我想在数组的所有索引中添加一个整数.不使用循环.in single ststement.

int a [4] = {4,4,4,4}; 我想在所有索引中添加1 ..所以输出是cout <

输出:_ 5 5 5 5

我相信所有人......

zeu*_*xcg 8

#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)

  • 抛开OP的问题,什么时候,*永远*,****在循环中的实践中发现它有用吗?:P (3认同)
  • @marcog,当他想表明谁的老板:P (3认同)
  • 这是一种混淆循环的迂回方式.+1! (2认同)