set的排序和去重以及遍历看下面程序,string是一个类所以不能把一个char型字符赋值给string,但是char型数组可以,
另外在不同的编译器上对于string以什么结尾的说法不一,最好不要用string的有效字符的后面一位来做一些事情。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<set>
using namespace std;
int main()
{
set<string> s;
string ss;
char x[205];
char c;
int len=0;
while((c=getchar())!=EOF)
{
if(isalpha(c))
{
c=tolower(c);
x[len++]=c;
}
else
{
x[len]='\0';
ss=x;
if(len)
s.insert(ss);
len=0;
}
}
// cout<<s.size()<<endl;
set<string>::iterator it;
for(it=s.begin();it!=s.end();it++)
cout<<*it<<endl;
return 0;
}