-1

I'm new to programming and one of the projects I would like to tackle would be a quiz, the problem is I do not know how to store my quiz scores in a text file, can someone help plz? A given example would be nice

Mat
  • 202,337
  • 40
  • 393
  • 406
Yiek St.
  • 1
  • 1
  • There is a list of good books [here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – molbdnilo Jun 04 '20 at 11:01

1 Answers1

2

Here is slightly modified example of the one given in cplusplus

// basic file operations
#include <iostream>
#include <fstream>

int main () {
  std::ofstream myfile("example.txt");
  if(myfile.is_open())
  {
     myfile << "Writing this to a file.\n";
     myfile << 1 << 2 << 3;
  }
  else 
  {
     std::cout << "error opening file" << std::endl;
  }
  return 0;
}

This creates example.txt in your working directory if it does not exist yet, opens it, streams to it and closes the file as myfile is destroyed. Now the file contains the following text:

Writing this to a file.
123
StefanKssmr
  • 1,196
  • 9
  • 16