为什么我C++的cout输出一个string,string的0输出为空格但是还继续输出下面的东西?

#include <iostream>
#include <string>

using namespace std;

string Func(string s)
{
bool boolset[256]={false};
int tail=0;
for(int i=0;i<(s.length());i++)
{
if(!boolset[s[i]])
{
boolset[s[i]]=true;
s[tail++]=s[i];
}
}
s[tail] = NULL;
return s;
}

int main()
{
while(true)
{
string x = "";
cin >> x;
cout << Func(x) << endl;
}
}
输入abccccde输出是abcde de.

string和char*是不同的,string里有长度信息,它不是以0结束的,改成:
//s[tail] = NULL;
s.resize( tail );
温馨提示:答案为网友推荐,仅供参考