使用C boost :: split拆分字符串而不拆分引用文本

我在用
boost::split(strs,r_strCommandLine,boost::is_any_of("\t "));

将字符串吐入标记以解析简单脚本.到现在为止还挺好.但是,对于以下字符串

command_name first_argument "Second argument which is a quoted string."

我想要我的代币

strs[0] = command_name
strs[1] = first_argument
strs[2] = "Second argument which is a quoted string."

当然,我可以在标记的开头和结尾搜索引号字符,并使用“”分隔符合并标记以引号开头的事件和以引号结束的标记间的标记,以重新创建引用的字符串,但我想知道如果有一种更有效/更优雅的方式来做到这一点.有任何想法吗?

解决方法

使用 boost::tokenizer的示例:
#include <string>
#include <iostream>
using std::cout;
using std::string;

#include <boost/tokenizer.hpp>
using boost::tokenizer;
using boost::escaped_list_separator;

typedef tokenizer<escaped_list_separator<char> > so_tokenizer;

int main()
{
    string s("command_name first_argument "
             "\"Second argument which is a quoted string.\"");

    so_tokenizer tok(s,escaped_list_separator<char>('\\',' ','\"'));
    for(so_tokenizer::iterator beg=tok.begin(); beg!=tok.end(); ++beg)
    {
        cout << *beg << "\n";
    }

    return 0;
}

输出

command_name
first_argument
Second argument which is a quoted string.

请参阅https://ideone.com/gwCpug的演示.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...