substr()方法 [英] substr() method in C++

查看:151
本文介绍了substr()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一些表达式子串到个别令牌,如!,& | (S& B | H)&!(S& J | R)&!(P)的子字符串。 (S& J | R)&!(P),当我认为它应该是:(S& J | R)。它或者是超出我所看到的或只是这么简单,我只是没有得到它。任何帮助将有很大帮助。感谢。

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


推荐答案

我不明白你的问题,但如果你想得到

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

(S&J|R)

您应该这样做:

name.substr )

name.substr(10,7)

第二个参数是长度。

这篇关于substr()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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