1,使用+=操作符
#include <iostream> using namespace std; #include <boost/thread.hpp> #include <boost/assign.hpp> using namespace boost; using namespace boost::assign; int main(int argc, _TCHAR* argv[]) { vector<int> v; v += 1,2,3,4,5,6*6; set<string> s; s += "cpp","java","c#","python"; map<int,string> m; m += make_pair(1,"one"),make_pair(2,"two"); return 0; }
2.使用()操作符
#include <iostream> using namespace std; #include <boost/thread.hpp> #include <boost/assign.hpp> using namespace boost; using namespace boost::assign; int main(int argc, _TCHAR* argv[]) { vector<int> v; push_back(v)(1)(2)(3)(4)(5); list<string> l; push_front(l)("cpp")("java")("c#")("python"); set<double> s; insert(s)(3.14)(0.618)(1.732); map<int,string> m; insert(m)(1,"one")(2,"two"); return 0; }