int start = 0;
int end = 0;
string temp = "<sasadfsadfsady>40000</sadsfasdfsadflary>";
for (int i = 0; i < temp.length(); i++){
if (temp[i] == '>' && start == 0) //will only save first one
start = i;
if (temp[i] == '<')
end = i-start; //will be overwritten by the second one
}
temp.erase(temp.begin(), temp.begin()+start+1);
temp.erase(temp.begin() + end-1, temp.end());
cout << endl;
cout << temp << end;
输出:
400006
为什么6结尾?我不知道为什么会这样,请帮帮我
答案 0 :(得分:6)
<< end
可能意味着
<< endl
现在输出6,因为int
变量end
的值为6。