如何复制阵列的部分到另一个数组 [英] How to copy portions of an array into another array

查看:118
本文介绍了如何复制阵列的部分到另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好!我需要一个阵列的一部分复制到另一个阵列开始在位置2和消费所有的剩余价值。第一个数组是类型'的argv数组的char **,但第二个数组必须是类型为const char *'的。看来,有两种方法在C ++中这样做 - STD:复制和memcpy。这将是更好地处理这种情况,因为这两个数组是不同类型的,哪些会为例会是什么样子?

Good morning! I need to copy a portion of one array into another array starting at position 2 and consuming all the remaining value. The first array is the 'argv' array of type 'char**' but the second array needs to be of type 'const char*'. It appears that there are two ways to do this in C++ - std:copy and memcpy. Which would be better to handle this situation since the two arrays are of different types and what would an example look like?

推荐答案

有在C ++使用的memcpy()很少有很好的理由。如果我理解你的要求正确地,这里有一个如何使用做一个例子的std ::复制()

There's very few good reasons to use memcpy() in C++. If I understand what you're asking correctly, here's an example of how to do it using std::copy().

vector<char*> args(argc - 2);
copy(argv + 2, argv + argc, begin(args));

活生生的例子

这篇关于如何复制阵列的部分到另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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