summaryrefslogtreecommitdiff
path: root/src/tools/FileTools.cpp
blob: bb5b7b534d07553dff6e7edf0f3c66f7b2288958 (plain)
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
#include "tgbot/tools/FileTools.h"

#include <fstream>
#include <sstream>
#include <string>

using namespace std;

namespace FileTools {

string read(const string& filePath) {
    ifstream in(filePath, ios::in | ios::binary);
    in.exceptions(ifstream::failbit | ifstream::badbit);
    ostringstream contents;
    contents << in.rdbuf();
    in.close();
    return contents.str();
}

void write(const string& content, const string& filePath) {
    ofstream out(filePath, ios::out | ios::binary);
    out.exceptions(ofstream::failbit | ofstream::badbit);
    out << content;
    out.close();
}

}