为什么我在输出结束时会得到额外的字符?

con*_*rio 0 c++ string char 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;
Run Code Online (Sandbox Code Playgroud)

输出:

400006
Run Code Online (Sandbox Code Playgroud)

为什么6结尾?我不知道为什么会这样,请帮助我

Ale*_*bin 6

<< end
Run Code Online (Sandbox Code Playgroud)

可能是应该的

<< endl
Run Code Online (Sandbox Code Playgroud)

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