《essential c++》第3章习题3.1中关于书上的解答我在输入后总会报错说改符号已在main中引用
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<iterator>
#include<fstream>
using namespace std;
void initialize_exclusion_set(set<string>&);
void process_file(const set<string>&, map<string, int>&, ifstream&);
void user_query(const map<string, int>&);
void display_word_count(const map<string, int>&, ofstream&);
int main()
{
ifstream ifile("w:\\c++practice\\essential c++\\column.txt");
ofstream ofile("w:\\c++practice\\essential c++\\column.map");
if (!ifile || !ofile)
{
cerr << "unable to open file--bailing out!\n";
return -1;
}
set<string>exclude_set;
initialize_exclusion_set(exclude_set);
map<string, int>word_count;
process_file(exclude_set,word_count, ifile);
user_query(word_count);
display_word_count(word_count, ofile);
}
void initialize_exclude_set(set<string>&exs)
{
static string _exclude_set[25] = {
"the","and","but","that","then","are","been","can","a",
"could","did","for","of","had","have","him","his","her","its","is",
"were","which","when","with","would"
};
exs.insert(_exclude_set, _exclude_set + 25);
}
void process_file(const set<string>&exclude_set, map<string, int>&word_count, ifstream& ifile)
{
string word;
while (ifile >> word)
{
if (exclude_set.count(word))
continue;
word_count[word]++;
}
}
void user_query(const map<string, int>& word_map)
{
string search_word;
cout << "please enter a word to search:(q to quit)\n";
cin >> search_word;
while (search_word.size() && search_word != "q")
{
map<string, int>::const_iterator it;
if ((it = word_map.find(search_word)) != word_map.end())
cout << "found! " << it->first << " occurs" << it->second << "times.\n";
else cout << search_word << " was not found.\n";
cout << "\nanother word to find?(q to quit)\n";
cin >> search_word;
}
}
void display_word_count(const map<string, int>&word_map, ofstream& os)
{
map<string, int>::const_iterator it = word_map.begin(),
end_it = word_map.end();
while (it != end_it)
{
os << it->first << " ("
<< it->second << ") "<< endl;
++it;
}
os << endl;
}
不知道是哪里出来问题,求解。