hex_refugeeeee 2021-10-04 12:07 采纳率: 50%
浏览 32
已结题

关于“该符号在main中已被引用”的问题

《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;
}

不知道是哪里出来问题,求解。

  • 写回答

1条回答 默认 最新

  • qfl_sdu 2021-10-04 12:44
    关注

    initialize_exclusion_set这个函数没实现。
    下面实现的函数initialize_exclude_set是不是名字写错了?

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月12日
  • 已采纳回答 10月4日
  • 创建了问题 10月4日

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算