-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiaryNote.cpp
More file actions
50 lines (40 loc) · 1.61 KB
/
Copy pathDiaryNote.cpp
File metadata and controls
50 lines (40 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "DiaryNote.hpp"
#include "Note.hpp"
#include <iostream>
#include <fstream>
#include "Utils.h"
using namespace std;
// Create a new diary note by asking the user for date and entry
void DiaryNote::create() {
cout << "----------------------------------------------\n";
cout << "Enter date (YYYY-MM-DD): ";
getline(cin, date); // Get the date from user input
cout << "Write your diary entry:\n";
getline(cin, entry); // Get the diary entry from user input
title = date; // Set the title to the date for consistency
}
// Display the diary note's date and entry
void DiaryNote::display() const {
cout << "----------------------------------------------\n";
cout << "Dairy Date: "; Utils::printYellow(date + "\n");
cout << "Entry:\n"; Utils::printYellow(entry + "\n");
}
// Save the diary note to a file in the specified user folder
void DiaryNote::saveToFile(const string& userFolder, const string& filename) const {
ofstream file(userFolder + "/" + filename); // Open file for writing
file << "DiaryNote\n" << date << "\n" << entry << "\n"; // Write note type, date, and entry
}
void DiaryNote::loadFromFile(ifstream& in) {
getline(in, date); // Correct: this is the 2nd line after "DiaryNote"
title = date; // Consistent with create() and display()
string line;
entry.clear();
while (getline(in, line)) {
entry += line + "\n";
}
}
// Return the type of the note as a string
string DiaryNote::getType() const {
return "DiaryNote";
}
//cout << "Diary Date: " << date << "\nEntry:\n" << entry << "\n";