使用Boost标记者escaped_list_separator使用不同的参数 [英] Using Boost Tokenizer escaped_list_separator with different parameters

查看:507
本文介绍了使用Boost标记者escaped_list_separator使用不同的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我一直试图让一个标记使用Boost库tokenizer类工作。
我发现这个教程升压文档上:

Hello i been trying to get a tokenizer to work using the boost library tokenizer class. I found this tutorial on the boost documentation:

http://www.boost.org/doc/库/ 1 _36 _0 /库/分词/逃​​脱_list _separator.htm

问题是我不能得到论证的,以逃脱_list _separator(,,);

problem is i cant get the argument's to escaped _list _separator("","","");

但如果我修改升压/ tokenizer.hpp文件,它的工作的。
但是这并不是理想的解决方案在想,如果有什么事,我很想念获得diferent参数进入逃脱_list _separator。

but if i modify the boost/tokenizer.hpp file it work's. but that's not and ideal solution was wondering if there's anything i am missing to get diferent arguments into the escaped _list _separator.

我希望把它分割与空间和转义和引用的字符串内没有转义字符。

i want to make it split on spaces with " and ' for escaping and with no escape character inside the quoted string.

这是用于在游戏中控制台系统参数解析系统。

this is used for a argument parsing system in a ingame console system.


include <iostream>
include <boost/tokenizer.hpp>
include <string>

INT的main()
{
    使用命名空间std;
    使用名字空间boost;
    字符串s =EXEC SCRIPT1 \\脚本参数一把手\\;
    字符串separator1(); //不要让报价参数逃脱自己
    字符串separator2(); //在空间分割
    字符串separator3(\\\\'); //让它有报价参数
    标记生成器&LT; escaped_list_separator&LT;焦炭&GT;(separator1,separator2,separator3)> TOK(S);
    对于(标记生成器&LT; escaped_list_separator&LT;&烧焦GT;(separator1,separator2,separator3)GT; ::迭代求= tok.begin();求= tok.end(!); ++ BEG)
    {
    COUT&LT;&LT; * BEG&LT;&LT; \\ n;
    }
}

int main() { using namespace std; using namespace boost; string s = "exec script1 \"script argument number one\""; string separator1("");//dont let quoted arguments escape themselves string separator2(" ");//split on spaces string separator3("\"\'");//let it have quoted arguments tokenizer<escaped_list_separator<char>(separator1,separator2,separator3)> tok(s); for(tokenizer<escaped_list_separator<char>(separator1,separator2,separator3)>::iterator beg=tok.begin(); beg!=tok.end();++beg) { cout << *beg << "\n"; } }


从Visual Studio 2005中错误的是
错误C2974:提振::标记生成器':为'TokenizerFunc无效的模板参数,类型有望

the error from visual studio 2005 is error C2974: 'boost::tokenizer' : invalid template argument for 'TokenizerFunc', type expected

编辑:
对此问题予以ferrucio awnsered并解释由彼得感谢各位。

This question was awnsered by ferrucio and explained by peter thank's everybody.

推荐答案

试试这个:

#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>

int main()
{
    using namespace std;
    using namespace boost;
    string s = "exec script1 \"script argument number one\"";
    string separator1("");//dont let quoted arguments escape themselves
    string separator2(" ");//split on spaces
    string separator3("\"\'");//let it have quoted arguments

    escaped_list_separator<char> els(separator1,separator2,separator3);
    tokenizer<escaped_list_separator<char>> tok(s, els);

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

这篇关于使用Boost标记者escaped_list_separator使用不同的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆