想在整数数组的所有索引中添加一个整数 [英] want to add an integer in all the indexes of the integer array

查看:97
本文介绍了想在整数数组的所有索引中添加一个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i want to add an integer in the all indexes of an array .without using loop .in single ststement.

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

输出:_
5
5
5
5

int a[4]={4,4,4,4}; i want to add 1 in all indexes.. so the out put is cout<

output:_ 5 5 5 5

i

推荐答案

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

这篇关于想在整数数组的所有索引中添加一个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆