Reputation: 1174
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;
output:
400006
why is the 6 at the end? I have no idea why this is happening, please help me
Upvotes: 0
Views: 110
Reputation: 2075
<< end
Was probably meant to be
<< endl
It outputs 6 now because the int
variable end
has value 6.
Upvotes: 6