没有匹配功能(输入/输出)

时间:2016-09-18 16:28:03

标签: c++ function input output

我正在编写一个使用输入/输出的程序,我的代码中有两个函数问题:copyTextprint。他们根本不工作,我无法理解问题的根源。我真的很感激任何帮助。谢谢!

#include <iostream>
#include <fstream>
#include <cctype>

using namespace std;

void initialize(int&, int[]);
void copyText (ifstream&, ofstream&, char&, int[]);
void count(char, int[]);
void print(ofstream&, int, int[]);

int main()
{
    int line;
    int letter[26];
    char ch;
    ifstream infile;
    ifstream outfile;
    infile.open("input.txt");
    outfile.open("output.txt");
    initialize(line, letter);
    infile.get(ch);
    while(infile)
    {
        copyText(infile, outfile, ch, letter);
        line++;
        infile.get(ch);
    }

    print (outfile, line, letter);
    infile.close();
    outfile.close();
    return 0;
}
void initialize(int& loc, int list[])
{
    loc = 0;
    for (int i =0; i <26; i++)
        list[i] = 0;
}

void copyText(ifstream& in, ofstream& out, char& ch, int list[])
{
    while (ch != '\n')
    {
        out << ch;
        count (ch, list);
        in.get(ch);
    }
    out << ch;
}
void count(char ch, int list[])
{
    ch = toupper(ch);
    int index = static_cast<int>(ch)-static_cast<int>('A');
    if (0 <= index && index < 26)
        list[index]++;
}
void print (ofstream& out, int loc, int list[])
{
    out << endl<< endl;
    out << " The number of lines is "<<loc <<endl;
    for (int i = 0; i<26; i++)
        out << static_cast<char>(i+static_cast<int>('A')) << "count =  " <<list[i] << endl;
}

0 个答案:

没有答案