ofstream woes.

I'd just like to find out, is it possible to export strings to files and then import them into the code later? I'm not sure if I've missed anything on the internet detailing this simply but those that I found, I could not understand. It would be great if someone could tell me how to export and then import them again, like a save file. Thanks! :)

Harry
closed account (SECMoG1T)
If by export and import you meant to write the strings to a file and then read them later then that's possible, you'll just require to use the ofstream "output file stream " to write the strings to the file, later you can use the ifstream stream to read the strings again to your program.

example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <fstream>
#include <string>

using namespace std;

int main ()
{
  ofstream out ("mystrings.txt", ios::app);
   /// check if the file opened successfuly
   
   out <</*write something to the file*/
   out.close ();
   /// more code here
  

  ifstream in ("mystring.txt");
  ///check if your stream is alright

  in>>/*read and use your previously saved data*/
  in.close ();
 }


Maybe that's all you were asking about.
Yes indeed, thank you, andy1992! Really helped.
Topic archived. No new replies allowed.