c++ - 如何将 std::array 转换为 std::vector?

标签 c++ arrays c++11 vector

我需要将 std::array 转换为 std::vector,但无论如何我都无法快速完成。这是示例代码:

 std::array<char,10> myData={0,1,2,3,4,5,6,7,8,9};

现在我需要创建一个 vector ,例如:

std::vector<char> myvector;

并用数组值初始化它。

最快的方法是什么?

最佳答案

您可以使用 constructor of std::vector采用迭代器。

Constructs the container with the contents of the range [first, last).

例如

std::array<char,10> myData = {0,1,2,3,4,5,6,7,8,9};
std::vector<char> myvector(myData.begin(), myData.end());

关于c++ - 如何将 std::array 转换为 std::vector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47754679/

相关文章:

c++ - 如何从根文件夹及其所有子文件夹生成目录树?

c++ - 在pkg-config和cmake找不到的介子中声明库依赖

python - OpenCV Python 不支持 src 数据类型 17 错误

arrays - 如何查找元胞数组中最后一个非空元素的索引

c++ - 为什么这个双重互斥锁不会造成死锁呢?

c++ - Qt 和 native 菜单

javascript - daySettings[2].replace 不是函数 jquery 日期选择器

C++11 在 int x, int y 之间随机,不包括 list<int>

c++ - 使用 std::string 作为缓冲区有缺点吗?

c++ - 为什么我无法通过外围设备进行身份验证?