[英]C++ 2d unordered_map with vector
我來自PHP,我會做的
$um['Im a string'][1] = 3;
對於2d關聯數組,其中第一個鍵是字符串,第二個鍵是整數,值也是一個整數。 我嘗試在c ++中執行相同的操作。 這是我的嘗試:
// experiment.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <unordered_map>
#include <vector>
#include <string>
using std::vector;
using std::string;
using std::unordered_map;
int _tmain(int argc, _TCHAR* argv[])
{
unordered_map <string,vector<int,int>> um;
um["Im a string"][1] = 3;
printf("Out: %d", um["Im a string"][1]);
return 0;
}
顯然,它的語法不正確;
vector<int,int>
是不正確的( vector
不是關聯容器),您可能需要嵌套的unordered_map<int>
。 所以:
unordered_map <string,unordered_map<int,int>> um;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.