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

Chr*_*lly 6 c++ boost split

我在用

boost::split(strs, r_strCommandLine, boost::is_any_of("\t "));
Run Code Online (Sandbox Code Playgroud)

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

command_name first_argument "Second argument which is a quoted string." 
Run Code Online (Sandbox Code Playgroud)

我想要我的代币

strs[0] = command_name
strs[1] = first_argument
strs[2] = "Second argument which is a quoted string." 
Run Code Online (Sandbox Code Playgroud)

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

hmj*_*mjd 15

示例使用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;
}
Run Code Online (Sandbox Code Playgroud)

输出:

command_name
first_argument
Second argument which is a quoted string.

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