安迪的第一本字典

#include <iostream>
#include <string>
#include <set>
#include <sstream>

using namespace std;

set<string> dict;
//集合set的用法:每个元素最多出现一次;   安迪的第一本字典;

int main()
{
    string s, buf;
    while(cin >> s)
    {
        for(size_t i =  0 ; i < s.length(); i++)
            if(isalpha(s[i]))
                s[i] = tolower(s[i]);
//如果是字母则将读入的单词全部转化为小写;
            else
                s[i] = ' ';
        stringstream ss(s);
        while(ss >> buf) //将读入的单词插入到set中去;
            dict.insert(buf);
    }
    for(set<string>::iterator it= dict.begin(); it!=dict.end(); it++)
        cout << *it << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/pprp/p/7193753.html