向量向量字符串固定大小

vector vector string fixed size

本文关键字:向量 字符串      更新时间:2023-10-16

我如何声明这样一个向量,像vector<vector<string>>vec(1)(2)使用vec[0][0]vec[0][1]而不使用push_back的动态大小。

using namespace std;
array< array< string, 2 >, 1 > vec;

std::vector用于动态大小的数组。std::array (c++ 11,或使用Boost库)用于固定大小的数组。

std::vector<std::vector<string>> vec(1, std::vector<string>(2));

则可以访问vec[0][0]vec[0][1]。(你可以改变矢量的大小)