0

Im trying to read from a file using classes and objects. i keep getting this error

main.cpp:16: error: no matching function for call to ‘Game::fillGame()’
Game.h:41: note: candidates are: bool Game::fillGame(std::ifstream&)

here is code that goes with the error

//Game.h

 bool fillGame(ifstream & din);
//Game.cpp

#include<iostream>
#include "Game.h"

bool Game::fillGame(ifstream &din)
{
int round_Of;
ifstream din;


    din.open("file.txt");
    if(!din)
        cout << "Error: file could not be found";
    else
    {
        din >> round_Of;
        while(!din.eof())
        {
            cout  << round_Of;
            din >> round_Of;
        }
        cout << endl << endl;
        din.close();
    }

}
//main.cpp

#include "Game.h"


#include<iostream>
#include<cstring>
#include<iomanip>
#include<cctype>
#include<fstream>
#include<string>

int main()
{
    Game output;
    output.fillGame();





    return 0;
}

Edited by clickspiker23: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by jonsca
0

I would just eliminate that parameter, as you are creating a new ifstream object within the body of the method anyway. You may want to rethink your implementation a bit, because all you are doing is writing to the same int value over and over again, and that int is being destroyed once you leave the method anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.