使用boost的xxx_list_of函數爲靜態容器map和vector等賦初值

#include <iostream>
#include <boost/assign.hpp> ///for map_list_of
#include <map>

using namespace std;
using namespace boost::assign;

static std::map<std::string,int> aMap = boost::assign::map_list_of("aaa",1)("bbb",2)("ccc",3);

int main()
{
    std::map<std::string,int>::iterator it;
    for(it = aMap.begin();it != aMap.end(); ++it)
    {
        std::string s = it->first;
        int n = it->second;
        cout <<"[" <<s <<","<<n<<"]"<<endl;
    }
    return 0;
}
///爲static vector<***> 的初始化方法類似map,不在贅述……

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章