急,急,急!!!
以下一段程序是要统计文章单词的问题!,出不来结果,问题出在哪呢?请达人门指教
#include "stdafx.h"
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <algorithm>
#include <utility>
using namespace std;
#include <stddef.h>
#include <ctype.h>
int _tmain(int argc, _TCHAR* argv[])
{
ifstream infile("1.txt",ios::in);
if(!infile)
{ cerr<<"unable to open file"<<endl;
exit(-1);
}
else cout<<endl;
vector<string> *lines_of_text=new vector<string> ;
string textline;
while (getline(infile,textline,'\n'))
lines_of_text->push_back(textline);
vector<string>*words=new vector<string> ;
for(short line_pos=0;line_pos < lines_of_text->size();line_pos++)
{ short word_pos = 0;
string textline=(*lines_of_text)[line_pos];
string::size_type eol=textline.length();
string::size_type pos=0,prev_pos=0;
while((pos=textline.find_first_of(' ',pos))!= string::npos)
{
words->push_back(textline.substr(prev_pos,pos-prev_pos));
word_pos++; pos++;prev_pos=pos;
}
words->push_back(textline.substr(prev_pos,pos-prev_pos));
locations ->push_back(make_pair(line_pos,word_pos));
}
//去除标点符号;
string filt_elems( "\",.;:!<< \\/" );
vector<string>::iterator iter = words->begin();
while ( iter!=words->end() );
{
string::size_type pos1 = 0;
while (( pos1 = ( filt_elems, pos1 ))!= string::npos )
(*iter).erase(pos1,1);
++iter;
}
for(vector<string>::iterator iter1=words->begin();iter1!=words->end();iter1++)
cout<<*iter1<<endl;
return 0;
}