C++11から、コンテナクラスの初期化ができる
map好きな自分用メモ(mapにmapを入れた場合の書き方)
a.cpp
# include <stdio.h>
# include <string>
# include <map>
int main( int , char ** ) {
std::map< std::string, std::map< std::string, std::string > > data =
{
{ "key1",
{
{ "key1_1", "a" },
{ "key1_2", "b" },
}
},
{ "key2",
{
{ "key2_1", "c" },
{ "key2_2", "d" },
}
},
};
for( auto &i: data ) {
printf( "%s\n", i.first.c_str() );
for( auto &o: i.second ) {
printf( "\t%s=%s\n", o.first.c_str(), o.second.c_str() );
}
}
return( 0 );
}
[todanano@localhost tmp]$ ./a.out
key1
key1_1=a
key1_2=b
key2
key2_1=c
key2_2=d
[todanano@localhost tmp]$