C++;substr并首先找到

C++;substr并首先找到,c,strtok,C,Strtok,我想改变我的问题 请告诉我发生了什么事 type is "CHAR(10)" size = type.substr(type.find_first_of("("), type.find_first_of(")")); cout << "SIZE : " << size << endl; cout << "SIZE : " << size.substr(1, (size.length())-1) << endl; SIZE

我想改变我的问题

请告诉我发生了什么事

type is "CHAR(10)"

size = type.substr(type.find_first_of("("), type.find_first_of(")"));
cout << "SIZE : " << size << endl;
cout << "SIZE : " << size.substr(1, (size.length())-1) << endl;

SIZE : (10)
SIZE : 10)
类型为“CHAR(10)”
size=type.substr(type.find_first_of(“”),type.find_first_of(“”);

std::string中的cout函数substr有两个参数 第一个参数是起始索引,第二个参数是所需子字符串的长度

string type = "CHAR(10)";

int k1,k2;
size = type.substr(k1=type.find_first_of("("), k2=type.find_first_of(")"));
cout<<"index="<< k1<<" len=" << k2 << endl;
cout << "SIZE : " << size << endl;
cout << "SIZE : " << size.substr(1, (size.length())-1) << endl;

index1=4 len=7
SIZE : (10)
SIZE : 10)

你说工作不好是什么意思给我们看看你的代码和你面临的问题。工作不好?正如在它的工作正常,但不是很好?我怎么可以张贴我的代码在这里?-,-不容易。@newmkka:编辑您的问题,粘贴代码,选择它,然后按CTRL+K组合键设置格式。这就是全部,等等,这是C还是C++?那个叫“推回”的电话让我怀疑。谢谢,我用int I,j=0做了这个样式;i=type.find_first_of(“(”)+1;j=type.find_first_of(“)”-i;
k1= type.find_first_of("(");
k2=type.find_first_of(")");
k2-=k1;//now it's the length of size
size = type.substr(k1,k2);