简体   繁体   中英

Why am I getting extra character at the end of my output?

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

<< end

Was probably meant to be

<< endl

It outputs 6 now because the int variable end has value 6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM