2
fstream file("afile.txt" , ios :: out | ios:: in | ios :: app);
if(!file.is_open())
{
    cout << "Error Loading File!";
}
else
{
    // cout << " File Created ";
}

for(i = 0 ; i < gameplayed ; i ++)
{

file <<name << " Won $"  << prize << " And Answered " << questions << " Questions" << "\n";

}
file.seekg(0);
string line;
while(file.good())
{

    getline(file,line);
    cout <<  line  ;
}

So basically the codes works perfectly and doesn't overwrite, but it just starts right after like

"Player Won $2000 Dollars And Answered 6 Questions Plater2 Won $2000 Dollars And Answered 6 Questions"

I want is To Appear Like With a line break and not after it

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185

2 Answers2

2

This will help you

Replace std::endl with "\r\n" to get CRLF instead of just LF.

Ibrahim.Sluma
  • 164
  • 13
1

Your output does have line breaks.

However, it doesn't have carriage returns.

If you're reading the file on Windows, in an app that makes a distinction, you won't "see" the break.

You may wish to consider writing \r\n instead, which is the standard line ending sequence on Windows.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055