I am trying to save information to a file but i do not want the user to input any information. I want to use a variable that is within the program already to set the save file variable. here is the code I am trying to get to work correctly.
void saveGame()
{
ofstream outFile("FiveCardNoPeekPoker.txt",ios::trunc);
if (outFile)
{
int savedChips ;
while (cin >> savedChips)
{
savedChips = CardDealer::startingChipsTotal;
}
outFile.close();
}
else
{
cout << "File not created!" << endl;
}
system("pause");
}
Right now it will save to the file but it requires the user to input a number and to exit it you have to hit ctrl +z and then enter. This is what I am trying to avoid.
void saveGame()
{
ofstream outFile("FiveCardNoPeekPoker.txt",ios::trunc);
//if (outFile) //not needed because even if the file is not there it'll be created base on the ios flags currently set
outFile << "This is being output to the file." << endl; //outfile is now used like cout
outFile << CardDealer::startingChipsTotal;
outFile.close();
}