我有 2 个字符串,来自 Sqlite3,ColName 和 Value。我想保存每对值,我不知道 ColName/Value 的数量,所以我使用 vector 。
有没有办法让我可以创建/推送一个 ColName/Value 到数组的 vector
代码:
std::vector<std::string[3]> colNameAndValueList;//this doesnt work
string colName="ID";
string value="122001";
colNameAndValueList.push_back(std::string(colName,value));//im lost here
我不知道我应该使用 hash 还是 struct,谁能给我一个建议?
谢谢。
最佳答案
我建议你使用一个std::vector
结构:
struct Name_Value
{
std::string name;
std::string value;
};
typedef std::vector<Name_Value> Name_Value_Container;
这更容易阅读、理解和实现。
关于c++ - 如何在 C++ 中创建数组 vector ( string [] ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29992941/