substr() method in C++

我们两清 提交于 2019-12-02 23:39:27

问题


I am trying to substring some expressions into individual tokens such as !, &, | (), etc. What I am having trouble with is the fact that when I try to make a sub-string of "!(S&B|H)&!(S&J|R)&!(P)" with the cout line below, I get: "(S&J|R)&!(P)", when I thought it should be: "(S&J|R)". It either is beyond what I have seen or just so simple that I just am not getting it. Any help would help a lot. Thanks.

#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {

string name = "!(S&B|H)&!(S&J|R)&!(P)";

cout<<name.substr(10,16)<<endl;


return 0;

}//Main

回答1:


I did not understand your question well but if you want to get

(S&J|R)

You should do:

name.substr(10,7)

The second parameter is the length.



来源:https://stackoverflow.com/questions/31465277/substr-method-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!