summaryrefslogtreecommitdiff
path: root/src/tools/FileTools.cpp
blob: 14c322c18874fc6f21b2530222c4b3c3246495aa (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
28
29
30
31
32
33
34
35
//
// Created by Oleg Morozenkov on 25.01.17.
//

#include "tgbot/tools/FileTools.h"

#include <fstream>
#include <sstream>

using namespace std;

namespace FileTools {

std::string read(const std::string& filePath) {
	ifstream in(filePath, ios::in | ios::binary);
	if (in) {
		ostringstream contents;
		contents << in.rdbuf();
		in.close();
		return contents.str();
	}
	throw errno;
}

bool write(const std::string& content, const std::string& filePath) {
	ofstream out(filePath, ios::out | ios::binary);
	if (out) {
		out << content;
		out.close();
		return true;
	}
	return false;
}

};