boost常用记录
1.BOOST_FOREACH
經常會遍歷容器,寫for/while循環到手痛,使用BOOST_FOREACH可以減少我們的工作。支持容器vector/list/set/deque/stack/queue #include <boost/foreach.hpp> BOOST_FOREACH(value,container){ //遍歷每個元素 }例子:
vector<int32_t> _v;BOOST_FOREACH(int32_t& value,_v) { //這里就可以修改/訪問value } std::map<int32_t,int32_t> _map; typedef const std::map<int32_t, int32_t>::value_type const_pair; BOOST_FOREACH(const_pair& node,_map) { //這里就可以訪問node的元素 int32_t key = node.first; int32_t value = node.second; }2.字符串切割
?
#include <boost/tokenizer.hpp> int split(const string& str, const string& strSep,vector<string>& vec) {typedef boost::tokenizer<boost::char_separator<char> > tokenizer;boost::char_separator<char> sep(strSep.c_str());tokenizer token(str, sep);tokenizer::iterator it = token.begin();for (; it != token.end(); ++it){ vec.push_back(*it);} return vec.size(); } </char></char></string>?
轉載于:https://www.cnblogs.com/whuqin/p/4981987.html
總結
- 上一篇: 代码Review发现问题
- 下一篇: 基于'sessionStorage'与'