Saving to a file

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 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.
1
2
3
4
5
6
7
8
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();
}

Last edited on
Thank you that worked perfectly. Its weird how the way i had it made it look so much more complicated than it needed to be.
amazingly complicated lol :p
never know tho, u might find it useful someday ~
Topic archived. No new replies allowed.