0

いくつかの段落かそこらを読む方法、各単語を構造に入れる方法、一意の単語がいくつあるかを数える方法がわかりません。

行のある文字列から単語を転送するのではなく、データを読み取る方法を知っています。そして、私が前に言ったように、いくつかの段落を読んでください

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;


struct words
{
    char unique[21];
    int count;
} test;

void inputFile (words essay[100]);
int search (int index, int subscript, int integer,words essay[100]);

int main()
{
    words essay[100];
    inputFile (&test);

    cout << essay[0].unique<<test.count;
    return 0;
}


void inputFile (words essay[100])
{
    char fileName[81];
    char copyName[81];
    cout << "What is the name of the input file? \n";
    cin >> fileName;


    ifstream infile;
    ofstream outfile;
    int count = 0;
    char line [81];
    int ch;
    infile.open(fileName);
    outfile.open(copyName);

    while ((ch = infile.peek()) != EOF)
    {   // while not end of file
        infile.getline (line[81].unique, 81);
        cout << "Copying: " << line << endl;


        count++;
        outfile << essay << endl;
    }

    cout << "There were " << count << " lines copied\n";
    cout << endl;
    // close both files
    infile.close ();
    outfile.close ();
 };


/*int search (int index, int subscript, int integer, struct words essay[100])
{
    string key;
    key = test.unique;
    int n;
    n = test.count;
    int i;
    i = 0;
    while (i < n && essay[i] != key)
    i++;
    if (i == n)
    {
        i = -1;
    }
    return i;
    };*/
4

1 に答える 1

0

これは部分的な回答であり、主にストリーム読み取りロジックのクリーンアップに焦点を当てています。これ以上助けを提供するのに十分な明確さであなたが何をしているのか理解できません。(たとえば、何も入れずに に出力essayするのはなぜですか。)outfile

void inputFile (words essay[100])
{
    std::string fileName, copyName;
    cout << "What is the name of the input file?\n";
    cin >> fileName;
    // I assume you get copyName here…
    // Though fileName and copyName really should be parameters
    // passed in from `main()`.

    ifstream infile(fileName);
    ofstream outfile(copyName);
    std::string line;
    int count = 0;
    while (getline(infile, line))
    {
        cout << "Copying: " << line << endl;
        count++;
        outfile << essay << endl; // No idea what you're doing here.
    }

    cout << "There were " << count << " lines copied\n";
};
于 2013-07-13T10:23:19.803 に答える