小编Sha*_*aun的帖子

C++ Boost:Split String

如何使用正则表达式将带有Boost的字符串拆分并在结果列表中包含分隔符?

例如,如果我有字符串"1d2"而我的正则表达式是"[az]"我希望结果在带有(1,d,2)的向量中

我有:

std::string expression = "1d2";
boost::regex re("[a-z]");
boost::sregex_token_iterator i (expression.begin (),
                                expression.end (), 
                                re);
boost::sregex_token_iterator j;
std::vector <std::string> splitResults;
std::copy (i, j, std::back_inserter (splitResults)); 
Run Code Online (Sandbox Code Playgroud)

谢谢

c++ regex string boost tokenize

3
推荐指数
1
解决办法
5025
查看次数

C++ RTTI和派生类

我的C++有点生疏.这是我正在尝试做的事情:

class Cmd { };
class CmdA : public Cmd { };
class CmdB : public Cmd { };
...
Cmd *a = new CmdA ();
Cmd *b = new CmdB ();
Run Code Online (Sandbox Code Playgroud)

第一个问题:

cout << typeid (a).name ()
cout << typeid (b).name ()
Run Code Online (Sandbox Code Playgroud)

两者都返回Cmd*类型.我想要的结果是CmdA*和CmdB*.除此之外的任何方式实现此目的:

if (dynamic_cast <CmdA *> (a)) ...
Run Code Online (Sandbox Code Playgroud)

其次,我想做这样的事情:

class Target {
    public:
        void handleCommand (Cmd *c) { cout << "generic command..." }
        void handleCommand (CmdA *a) { cout << "Cmd A"; }
        void handleCommand (CmdB *b) { …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance rtti

2
推荐指数
1
解决办法
2018
查看次数

标签 统计

c++ ×2

boost ×1

inheritance ×1

regex ×1

rtti ×1

string ×1

tokenize ×1