アンディの最初の辞書


質問の説明:1つのテキストを入力して、すべての異なる単語(連続するアルファベットのシーケンス)を探し出して、辞書の順序によって小さいから大きいまで出力して、単語は大文字と小文字を区別しません.
あまりテクニックがないのでstringstreamとsetの使い方に注意すればいいです(vs 2012実行通過):
// 10815.cpp :              。
//

#include "stdafx.h"
#include<string>
#include <iostream>
#include <fstream>
#include <set>
#include <sstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	//ifstream in("data.txt");
	set<string> dict;
	string str,buf;
	while(cin>>str)
	{
		for(int i=0;i<str.size();i++)
		{
			if(isalpha(str[i]))
			{
				str[i] = tolower(str[i]);
			}
			else
			{
				str[i] = ' ';
			}
		}
		stringstream ss(str);
		while(ss>>buf)
		{
			dict.insert(buf);
		}
	}
	for(set<string>::iterator i = dict.begin();i!=dict.end();i++)
	{
		cout<<*i<<endl;
	}
	return 0;
}