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

时间:2015-07-17 20:29:45

标签: 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;

输出:

400006

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

1 个答案:

答案 0 :(得分:6)

<< end

可能意味着

<< endl

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