To pass an ifstream type as an argument for a function?
bool initGame(Game &game, int argc, char *argv[]){
ifstream board(argv[1]); // <------------------- This part
ifstream deck(argv[2]);
int numPlayers= atoi(argv[3]);
int numRounds= atoi(argv[4]);
if (board.fail() || deck.fail()
|| numPlayers==0 || MAXPLAYERS < numPlayers
|| numRounds < 1 || numRounds > 1000
|| (strcmp(argv[5], "yes") && strcmp(argv[5], "no")))
{
cout<< "Improper arguments." << endl;
exit(1);}
else{
initBoard(board); // <------------ This part
return true;}
}
I was going to use a separate function to read the data from the file as needed, but I get compiling errors if I try this:
void initBoard(ifstream board){
string squares;
getline (board, squares, '\n');
cout << squares;}<------------ For testing purposes, will do other stuff l8r
Any help would be appreciated, as I'm considering taking some very very drastic coding measures to get this to work if I cannot figure it out soon. And really, nobody wants that.