给定一个2D数组,其中每个(x,y)单元包含一个不同大小的字符串向量(为了简单起见)。
将此数据结构扁平化为一维数组的最有效方法是什么,即创建一个函数,将每个字符串注入到{1,。。。,n},其中n是数据结构中字符串的总数。
谢谢你的帮助
简单直接的方法不适合你吗?
#include <vector>
#include <string>
int main() {
std::vector<std::string> omg[3][4];
std::vector<std::string> rv;
for(auto const &row: omg) {
for(auto const &cell: row) {
for(auto const &str: cell) {
rv.push_back(str);
}
}
}
}