/ Published in: C++
Expand |
Embed | Plain Text
#include <cstdlib> #include <iostream> #include <fstream> #include <string> #include <algorithm> using namespace std; void logWriteTo() { ofstream myLog; string command; string logWrite; myLog.open("log.txt", ios::app); cout << "new entry?" << endl; cin >> command; if (command == "yes") { system("cls"); cin >> logWrite; myLog << ">>> " << logWrite << "\n\n"; } myLog.close(); ; } void logView() { cout << "your recent entries:\n\n\n" << endl; system("cls"); string line; ifstream myLog ("log.txt"); if (myLog.is_open()) { while ( myLog.good() ) { getline (myLog, line); cout << line << endl; } myLog.close(); system("pause"); } } int main() { string command; cout << "would you like to use the logwriter?" << endl; cin >> command; if (command == "yes") { logWriteTo(); logView(); } } //input: ">>> hello.how.has.your.day.been?" (sadly, I have no idea how to input white spaces //with cin yet.)
You need to login to post a comment.
