0
void putDataInBook(addressBookType& addType) {
    ifstream input_file();
    char file[40];
    string f1, l1, adds, c, st, code, num, relation;
    int mth, day, yr, count=0;
    extPersonType extPerson;

    cout << "Please enter the file name: ";
    cin>>file;

    input_file.open(file);

    if(!input_file) {
        cout << "The file name you entered seems not is not valid."<<endl;
    }

    getline(input_file, f1);
    getline(input_file, l1);
    input_file>>mth>>day>>yr;
    getline(input_file, adds);
    getline(input_file, c);
    getline(input_file, st);
    getline(input_file, code);
    getline(input_file, num);
    getline(input_file, relation);

    while(input_file) {
        extPerson.setData2(f1, l1, mth, day, yr, adds, c, st, code, num, relation);
        addType.insertAt(count, extPerson);

        count++;
        input_file >> f1 >> l1 >> mth >> day >> yr;
        getline(input_file, adds);
        getline(input_file, c);
        getline(input_file, st);
        getline(input_file, code);
        getline(input_file, num);
    }
}

void diskData(addressBookType& addType) {
    ofstream output_file;
    char file[40];
    cout << "Please enter a file name." << endl;
    output_file.open(file);
    if(!output_file) {
        cout<<"The file does not exist.."<<endl;
    }
    addType.diskData(output_file);
}

以下是我的错误:

main2.cpp:128: error: no matching function for call to ‘getline(std::ifstream (&)(), std::string&)’

main2.cpp:129: error: no matching function for call to ‘getline(std::ifstream (&)(), std::string&)
4

1 回答 1

1

您声明了一个input_file返回std::ifstream. 您想删除括号或用花括号替换它们或传递文件名:

std::ifstream file1;
std::ifstream file2{};
std::ifstream file3(filename);
于 2013-09-23T01:42:04.530 回答