Saving in a program?

Im a beginner programmer and I have written a really simple program as practice. In the program it asks if you want to create a new account. If you say yes then it`ll take you through the steps of making it..but once I close the program it isnt going to save. How do I get it to save? I saw somewhere it said to save as a byte or as text or something but I dont know what that means. Hopefully this makes sense. Thanks
If you need to save it into a txt file you can use filestreaming. You need to include the <fstream> header.

The actual code to do this is is:

1
2
3
4
5
6
7
8
9
10
11
#include <fstream> //Needed for filestreaming
#include <iostream>
using namespace std;

int main()
{
   string name = "PaulthePenguin";  //Declare a string called name that's equal to "PaulthePenguin"
   ifstream writeTo("Filename.txt");  //Declare an ifstream (in filestream) called writeTo, that writes to "Filename.txt"
   writeTo >> name;  //writeTo is similiar to cin, except it writes a variable to a file.
   return(0);
}
Last edited on
That reads a variable from file.
Google around "c++ serialization" for loads of information about saving/reading class data to/from file.
Oops. My bad :p you would need an ofstream, not ifstream.
Thanks for the info guys! Im gonna get on that today!
Topic archived. No new replies allowed.