the exclusive word set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <map>
#include <vector>
#include <iostream>
#include<fstream>
using namespace std;
void restricted_wc(ifstream &removeFile, map<string, int> &wordCount)
{
vector<string> excluded;
string removeWord;
while(removeFile>>removeWord)
excluded.push_back(removeWord);
cout<<"Enter text(Ctrl+Z to end): "<<endl;
string word;
while(cin>>word)
{
bool find = false;
vector<string>::iterator iter = excluded.begin();
while(iter != excluded.end())
{
if(*iter == word)
{
find = true;
break;
}
++iter;
}
if(!find)
++wordCount[word];
}
}
int main()
{
map<string, int> wordCount;
string fileName;
cout<<"Enter fileName: "<<endl;
cin>>fileName;
ifstream exFile(fileName.c_str());
if(!exFile)
{
cout<<"error: can not open file: "<<fileName<<endl;
return -1;
}
restricted_wc(exFile, wordCount);
cout<<"word\t\t"<<"times"<<endl;
map<string, int>::iterator iter = wordCount.begin();
while(iter != wordCount.end())
{
cout<<iter->first<<"\t\t"<<iter->second<<endl;
iter++;
}
system("pause");
return 0;
}
|
why when I typed input.txt and then I typed hellow and pressed enter, it didn't show me anything? very confused :(
You have to press Ctrl+Z (Ctrl+D on Linux).
I press ctrl+z but it shows ^z, still do nothing
Topic archived. No new replies allowed.