array to vector
#include <vector>
constexpr int vec_size = 5;
float a[vec_size] = {0, 1, 2, 3, 4};
std::vector<float> vec_a(a, a + vec_size); // good
- https://sites.google.com/site/hashemian/home/tips-and-tricks/copy-array-cpp
- https://stackoverflow.com/questions/8777603/what-is-the-simplest-way-to-convert-array-to-vector
- https://www.freecodecamp.org/news/cpp-vector-how-to-initialize-a-vector-in-a-constructor/ <- how to initialize a vector from an array in C++
And vector to array
#include <vector>
constexpr int vec_size = 5;
float a[vec_size] = {0, 1, 2, 3, 4};
std::vector<float> vec_a(a, a + vec_size); // good
#include <algorithm>
float b[vec_size] = {}
std::copy(vec_a.begin(), vec_a.end(), b); // good
No comments:
Post a Comment