-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsFileManager.cpp
More file actions
50 lines (46 loc) · 1.24 KB
/
SettingsFileManager.cpp
File metadata and controls
50 lines (46 loc) · 1.24 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 "SettingsFileManager.h"
#include <stdexcept>
#include <iostream>
// Constructor
Settings_File_Manager::Settings_File_Manager()
{}
// Destructor
Settings_File_Manager::~Settings_File_Manager() {}
// load_settings
std::vector<std::string> Settings_File_Manager::load_settings()
{
// get the settings from a csv file and return them
std::vector<std::string> settings;
std::string s;
settings_file.open("settings.csv", std::fstream::in);
if (settings_file.is_open())
{
while (std::getline(settings_file, s, ','))
{
settings.push_back(s);
}
settings_file.close();
}
else
{
throw std::runtime_error("Cannot find settings file.");
}
return settings;
}
// save_settings
void Settings_File_Manager::save_settings(std::vector<std::string> settings)
{
// store settings from the application back into the csv file
settings_file.open("settings.csv", std::fstream::out);
if (settings_file.is_open())
{
settings_file << settings[0] << ",";
settings_file << settings[1] << ",";
settings_file << settings[2];
settings_file.close();
}
else
{
throw std::runtime_error("Cannot find settings file.");
}
}