惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V2EX - 技术
V2EX - 技术
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
Webroot Blog
Webroot Blog
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
H
Heimdal Security Blog
H
Help Net Security
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
F
Full Disclosure
小众软件
小众软件
S
Securelist
罗磊的独立博客
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
S
Schneier on Security
D
DataBreaches.Net
M
MIT News - Artificial intelligence
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
T
Tenable Blog
The Register - Security
The Register - Security
C
Check Point Blog
AWS News Blog
AWS News Blog
Cloudbric
Cloudbric
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
博客园 - 叶小钗
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美

博客园 - 撬棍

【.Net】2、8、16进制转换 【.Net】执行CMD命令 【.Net】获取随机数函数 【.Net】注册程序开机启动 【.Net】把窗体“钉”到桌面上 【.Net】多语言查看MSDN 【.Net】 显示星期字符串 【.Net】 判断时间字符串正确性 【.Net】 实现窗口拖动 【.Net】 Winform 单例运行实例 [C++]函数返回值 [C++]数组参数 [C++]const的指针使用 [C++]指针类型出参 [VBA]Excel输出utf-8编码格式文件 使用WideCharToMultiByte [C语言学习]之打印万年历 - 撬棍 - 博客园 [VB6.0]让程序在任务列表和资源管理器“隐身” [InstallShield]FindAllFiles与SetFileInfo配合实现文件加多文件属性设置 [VB]修改注册表让程序开机自动运行 - 撬棍 - 博客园
【C++】split
撬棍 · 2011-03-20 · via 博客园 - 撬棍

--------------------------------------------------1-------------------------------------------------------------------

void split(const std::string& src)
{
    stringstream ss;
    ss << src;
    while (!ss.eof())
    {
        std::string content;
        std::getline(ss, content, '|');
        std::cout << content << std::endl;
    }
}

--------------------------------------------------2-------------------------------------------------------------------

#include   <vector> 
#include   <string> 
#include   <boost/algorithm/string.hpp> int main()   

std::string str("1-56-89-52-41-56 "); 
std::vector <std::string> result; 
boost::algorithm::split(result, str, boost::algorithm::is_any_of( "- ")); 

}

--------------------------------------------------3-------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////// 

// Function Name     : split 

// Description       : split "source" with "delims" into string vector. 

// Input Parameters : source -- the string with spliter

//                      delims -- the spliters 

//                      vec     -- output

//                      result -- string vector

// Return Value      : how many slice had found.

////////////////////////////////////////////////////////////////////////////// 

size_t split(const std::string& source,

              const char *delims,

              std::vector <std::string> &vec,

              bool keepEmpty /*= false*/)

{

    // find the index of which not delims

    std::string::size_type beg = source.find_first_not_of(delims); 

    std::string::size_type end; 

    std::string::size_type nextBeg = beg; 

    while(std::string::npos != beg)

    { 

        //find the index which is delims, than [beg, end] is the slice we want

        end = source.find_first_of(delims, nextBeg + 1);

        nextBeg = end; 

        if(end < beg)

        {

            //we find that case : two delims

            if(keepEmpty)

            vec.push_back(" ");

        }

       else if(std::string::npos != end)

        {

            vec.push_back(source.substr(beg, end - beg));

            //update the begin index from the end index

            beg = source.find_first_not_of(delims, nextBeg);

        }

        else

        {

            vec.push_back(source.substr(beg));

            break;

        }

    }

    return vec.size();

}