c++删除元素问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 05:57:15
删除重复元素,其他元素按输入元素输出,怎么做?(方法越基础越好……THX)

//用到了stl中的两个类string vector,调试通过
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
string str;
cin>>str;
vector<char> temp;
for(int i=0; i<str.size(); i++)
{
int j=0;
int flag=1;
while(j<temp.size())
{
if(temp.empty())
break;
if(str[i]==temp[j])
{
flag=0;
break;
}
j++;
}
if(flag==1)
{
temp.push_back(str[i]);
}
}
for(int k=0;k<temp.size();k++)
cout<<temp[k];
cout<<endl;
return 0;
}