Browse Source

Added ability to change file open mode in the writeToTextFile function. Also added turnicate mode to the openFile function.

master
DomtronVox 1 year ago
parent
commit
75525a5856
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      src/Configuration/FileOperations.h

+ 4
- 2
src/Configuration/FileOperations.h View File

@ -175,6 +175,8 @@ std::fstream openFile(std::string filepath, char mode='w') {
std::fstream file;
if (mode == 'r') {
file.open(filepath, std::fstream::in);
} else if (mode == 't') {
file.open(filepath, std::fstream::out | std::fstream::trunc);
} else {
file.open(filepath, std::fstream::in | std::fstream::out | std::fstream::app);
}
@ -183,11 +185,11 @@ std::fstream openFile(std::string filepath, char mode='w') {
}
//write given string content to file at filepath
void writeToTextFile(std::string filepath, std::string msg) {
void writeToTextFile(std::string filepath, std::string msg, char mode='w') {
//open file for read and writing
std::fstream file = openFile(filepath);
std::fstream file = openFile(filepath, mode);
//if the file opened correctly write the message to it
if (file.is_open()) {


Loading…
Cancel
Save