[英]Accessing element of map of vector of maps (c++)
我一直在進行簡單的數據庫系統管理,並且提出了:
std::map< std::string, std::vector < std::map < std::string,
boost::variant <std::string, size_t, double bool> > > tables;
我有一個地圖(表),一個向量(表),一個地圖(記錄),我已經准備好編寫一個函數來讀取文件,但是我不確定如何訪問單個屬性。
我可以用以下命令打印整個內容:
for(auto table: tables)
for(auto record : table.second)
for(auto attribute : record) {
std::cout << j.second;
我嘗試做類似的事情:
std::cout << tables["credentials"][2]["username"];
但是,這不起作用。 它只打印空白行。
您很可能使用了錯誤的地圖鍵來訪問數據庫。
更新代碼以打印數據庫的內容,以便您也可以在地圖中查看鍵。
for(auto table: tables)
{
std::cout << "Key: " << table.first << std::endl;
for(auto record : table.second)
{
for(auto attribute : record)
{
std::cout << "Key: " << attribute.first
<< ", Value: " << attribute.second << std::endl;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.