简体   繁体   中英

vector vector string fixed size

我如何声明这样的向量,如何使用vec[0][0]vec[0][1]这样的vector<vector<string>>vec(1)(2)而不使用带有push_back尺寸。

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

std::vector is for dynamic size arrays.
std::array (C++11, or use Boost library) is for fixed size arrays.

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

Then you can access vec[0][0] and vec[0][1] . (You can change the size of the vector though).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM