set<char*>Word;ofstream ofs("c://word.txt",ios_base::app);
//按给定的标点来拆分单词void SplitString(const string&str){ size_t nlen = str.length(); char *strDest = new char[nlen + 1]; strcpy(strDest,str.c_str()); char *flag =",.!:<>?";
char *p = strtok(strDest,flag); while(p) { //cout<<p<<"/n"; Word.insert(p); ofs<<p<<"/n"; p = strtok(NULL,flag); } delete[]strDest; }
int _tmain(int argc, _TCHAR* argv[]){
ifstream ifs("c://Music.txt"); if (!ifs.is_open()) { cout<<"open file failed/n"; return 0; }
istream_iterator<string>ii(ifs); istream_iterator<string>eof; for_each(ii,eof,SplitString);
//将文件中分离的单词写入到文件中 if (!ofs.is_open()) { cout<<"open file failed/n"; return 0; }
ifs.close(); ofs.close(); system("pause"); return 0;}