zoukankan      html  css  js  c++  java
  • 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>



  • 相关阅读:
    QtDBus编程详解
    QProcess详解
    python 爬虫 亚航 指定日期间的航线
    python 模块
    centos postgres 安装、远程连接
    python 爬虫 anyproxy
    python_scrapy_filespipe重写
    python_xpath
    常见问题汇总
    python_scrapy_log日志
  • 原文地址:https://www.cnblogs.com/whuqin/p/4981987.html
Copyright © 2011-2022 走看看