Member-only story
C++ Diary Application — Write and Save Daily Entries
Introduction
A personal diary is a great way to keep track of your thoughts, memories, and experiences.
This simple C++ diary application allows you to write, save, and view daily journal entries.
The program lets you create multiple entries, stores them in a text file, and ensures your diary remains safe and easy to access.
Objective: The goal of this program is to provide users with a simple, efficient way to maintain a digital diary. It allows users to write daily entries, save them with a timestamp, and retrieve them as needed, all through a console-based C++ program.
Code
#include #include #include #include using namespace std; void writeEntry() { ofstream diaryFile; string entry; // Open diary file in append mode diaryFile.open("diary.txt", ios::app); if (!diaryFile) { cout << "Error opening diary file!" << endl; return; } // Get current date and time time_t now = time(0); char* dt = ctime(&now); // Write date and entry to file diaryFile << "Date: " << dt; cout << "Enter your diary entry (type 'EXIT' to stop writing):" << endl; // Get user input for diary entry while (true) { getline(cin, entry); if (entry == "EXIT") break; diaryFile << entry << endl; } diaryFile << "------------------------------------\n\n"…