Accessing Text Files

Hello, I am currently working on a simple program I can use to log user activity on a computer. Yes, I know, it's useless, but I can't think of anything better to use C++ to access text files for. Right now I can take user input and force it into a text file I call log.txt. What I would like to be able to do is take the previous log entry and add it back to the old one. Right now what the code does is it takes the file, opens it and then writes to the text file. It doesn't respect the fact that there used to be old log entries in there. If anyone can help me get the program to access the old entry and save it as a string, say oldLog and then add that to the current log along with the latest data. Here's my code so far. Thank you.
/*
Name: Computer Usage Log
Author: Dacoda Nelson
Date: 09/05/08 09:43
Description: A program for monitoring computer usage. The user inputs their
login information and reason for using. This is logged to a text
file and can be retrieved at a later time
*/

#include <iostream>
#include <stack>
#include <string>
#include <fstream>

using namespace std;

int main()
{
cout << "Hello, welcome to the computer usage monitoring system" << endl << "Please enter for the following information:" << endl;
cout << "Name: ";
string nameInput;
string timeInput;
string reasonInput;
getline (cin, nameInput);
cout << endl << "Time: ";
getline (cin, timeInput);
cout << endl << "Reason for accessing the system: ";
getline (cin, reasonInput);
ofstream logFile;
ifstream oldLog("log.txt");
logFile.open ("log.txt");
logFile << nameInput + " || " + timeInput + " || " + reasonInput + "\n";
logFile.close();
cout << "Press enter key to exit the system";
cin.get();
return 0;
}
 
http://www.cplusplus.com/reference/iostream/ofstream/open.html 

Check out the mode flags.

Hope this helps.
Hey, this is pretty great. Thanks, I hadn't seen this page. I'll try it out and see if it works.
Topic archived. No new replies allowed.