1

guys. My program based on class and read strem from file I use operator<< to read from file. I have a problem with display last record frmo file - last record display two times.

void Model::showDatabase() {

    cout << "Show database" << endl;
    ifstream file(db);
    string line;

    const int maxIgnore = 1;
    const int delim = ' ';
    string val1, val2;

    const char separator = ' ';
    const int nameWidth = 6;
    const int numWidth = 8;
    int i=1;

    cout << "\t\t Id. \t\t Numer \t\t Nazwa plyty" << endl;

    while(file)
    {
        file>>val1;
        file>>val2;

        cout << "\t\t "<<i<<"\t\t"<<val1<<"\t\t"<<val2<<endl;

        i++;
    }

}

and my overload method

ostream& operator <<(ostream& myIn, Record& record)
{
    cout << "save to file";

    myIn << record.idRecord;
    myIn << " ";
    myIn << record.cdName;
    myIn << "\n";
   // myIn << "==\n";

    return myIn;
}

and the last record from file shows 2x

lukassz
  • 3,135
  • 7
  • 32
  • 72

0 Answers0