为什么我在输出的末尾得到额外的字符?

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

本文关键字:字符 输出 为什么      更新时间:2023-10-16
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在最后?我不知道为什么会发生这种情况,请帮助我

<< end

应该是

<< endl

它现在输出6,因为int变量end的值为6。