1

私はPHPから来ています

$um['Im a string'][1] = 3;

最初のキーが文字列、2番目のキーが整数、値が整数である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;
}

明らかにそれは正しい構文ではありません。

4

1 に答える 1

2

vector<int,int>正しくない(vector連想コンテナではない)場合は、ネストされたが必要になる可能性がありますunordered_map<int>。それで:

unordered_map <string,unordered_map<int,int>> um;
于 2012-10-24T21:49:06.417 に答える