saving in c++

im trying to make a diary program.is there a way i can let the user save the diary entries they enter?
You can write to a file and then read that file in the future to get the data back.
do you know a tutorial on how to do that?
use <fstream> library
and output the entries to a .txt file
Additional info that may or may not be desired follows ;P

Given that this is for a "diary," if you want the saved data to be unreadable outside of the program, you may want to look into encryption. A method of encryption which balances a good deal of simplicity/understandability with a little bit of sophistication is to XOR the characters of the data against a repeated passphrase that only you and the diary program know. Example: suppose your passphrase is "go" (you would want to use something much longer and more complicated than that, though). Then "Dear diary" would be encrypted as follows:

First byte: D xor g
Second byte: e xor o
Third byte: a xor g
Fourth byte: r xor o
...and so on, where the first input to XOR is the byte from the plain text, and the second input is the next character from your passphrase, looping back to the beginning of the passphrase after reaching its end.

The convenient thing about this method is that XOR'ing the encrypted data against the same passphrase will take it right back to the original plain text. In other words, the decryption procedure is exactly the same as the encryption procedure. Like flipping a light switch on and off to encrypt/decrypt the data.
ok i started the program.but know how would i let the user open the older files and is there a way to let the user make a new file for a new journal entry by themselves?

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

using namespace std;

int main()
{
    string entry;

    ofstream entry1;
    entry1.open("entry1.txt");

    cout << "Enter your first journal entry.It can be up to 1000 characters: " << endl << endl;
    getline(cin, entry);
    entry1 << entry;

    cin.get();
    return 0;
}
but know how would i let the user open the older files and is there a way to let the user make a new file for a new journal entry by themselves?


You've got to start thinking about these things for yourself. We can't be here forever telling you what to do.


how would i let the user open the older files
1
2
3
4
5
6
cout << "Do you want to open an older file?";
cin >> input;
if (input == 'y')
{
  // do something to open the older file
}
You are completely capable of thinking of that yourself.
Here's a hint. The 'o' and 'f' in "ofstream" stand for "output file."
Topic archived. No new replies allowed.