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

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

问题描述

我想在一个数组的所有索引添加。没有使用循环。在单ststement一个整数。

int类型的[4] = {4,4,4,4};
我想在所有索引加1 ..
所以放出来的
COUT<

输出:_



5

我relly thnks所有..


解决方案

 的#include<功能>
#包括LT&;&算法GT;诠释的main()
{
    诠释一个[] = {1,2,3,4};    性病::变换(A,A +的sizeof(A)/ sizeof的(A [0]),一,的std :: bind1st(的std ::加< INT>(),1));
}

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}; i want to add 1 in all indexes.. so the out put is cout<

output:_ 5 5 5 5

i relly thnks to all..

解决方案

#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天全站免登陆