저는 파이썬 사전을 C++으로 모방하려고합니다. 예를 들어, 다음과 같은 것을 만들고 싶습니다.다중 레벨 사전 작성 : 파이썬에서 C++ 로의 변환
{"The Dark Night Rises": {"year": 2012, "StoryLine": "this is the story.....", "Genres": ["action","crime","Thriller"]}}
저는 이러한 종류의 사전을 구축하기 위해 STL 맵과 목록을 사용하고 있습니다. 그러나 iterators를 사용하는 방법을 잘 모르겠습니다. 위의 사전을 작성하는 예를 들어 도와 줄 수 있습니까? {"cast":["action","crime","Thriller"]}
과 같은 간단한 사전을 만들기 위해 아래에서 시작했습니다. 위에서 언급 한 다단계 사전을 작성하는 방법을 혼란스럽게하고, 특별히 다단계 사전을 반복합니다.
#include<iostream>
#include<string>
#include<map>
#include<iterator>
#include<list>
using namespace std;
class MultiLevDict
{
private:
list<string> lis;
map<string,list<string> > MultiDict;
public:
void Setter();
void Display() const;
};
void MultiLevDict::Setter()
{
string field;
string cast;
int sizeCast;
cout<<"enter the field of the movie:";
cin>>field;
cout<<endl;
cout<<"how many cast are there in this movie?:";
cin>>sizeCast;
for (int i=0; i<sizeCast; i++)
{
cin>>cast;
lis.push_back(cast);
}
MultiDict[field]=lis;
}
void MultiLevDict::Display() const
{
list<string>::iterator lisIt;
}
'multimap'에'list's의'지도'를 선호에 대한 특별한 이유는? –
@Zhenya. 나는 아무것도 신경 쓰지 않았다. –
@ JohanLundberg. 지도에 여러 개의 데이터 유형을 저장할 수있는 방법을 묻는 질문으로 내 질문을 확장하고 싶습니다. 예를 들어 map>을이 맵에 선언하면 문자열의 키와 목록 유형의 값을 저장할 수 있습니다. 이제 { "someval": [ "val1"], "somval2" "여기에 문자열", "someval3": 24}. 나는 [CODE] [http://www.dreamincode.net/forums/topic/129708-c-map-with-multiple-data-types/] 링크를 발견했다. 그 링크를보고 나서 나는 >과 같은 것을 생각하고있다. –
Rkz