From f26e8402cf886fbb49ef7047024d40b3fc2bfe17 Mon Sep 17 00:00:00 2001 From: Oleg Morozenkov Date: Sat, 10 Mar 2018 15:17:40 +0300 Subject: Fixes #55 --- .gitignore | 3 ++- include/tgbot/tgbot.h | 2 +- src/tools/FileTools.cpp | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 01735f9..7ba713b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ Thumbs.db doc/ *.cbp *.a -test/TgBot_test \ No newline at end of file +test/TgBot_test +.vscode/ \ No newline at end of file diff --git a/include/tgbot/tgbot.h b/include/tgbot/tgbot.h index b9d93c3..a6efd62 100644 --- a/include/tgbot/tgbot.h +++ b/include/tgbot/tgbot.h @@ -72,7 +72,7 @@ * @defgroup tools * * @mainpage - * [Go to GitHub](https://github.com/reo7sp) + * [Go to GitHub](https://github.com/reo7sp/tgbot-cpp) * * @section lib_compile Library compilation * diff --git a/src/tools/FileTools.cpp b/src/tools/FileTools.cpp index 14c322c..105d80f 100644 --- a/src/tools/FileTools.cpp +++ b/src/tools/FileTools.cpp @@ -11,25 +11,25 @@ using namespace std; namespace FileTools { -std::string read(const std::string& filePath) { +string read(const string& filePath) { ifstream in(filePath, ios::in | ios::binary); - if (in) { - ostringstream contents; - contents << in.rdbuf(); - in.close(); - return contents.str(); + if (!in) { + throw system_error(errno, system_category()); } - throw errno; + ostringstream contents; + contents << in.rdbuf(); + in.close(); + return contents.str(); } -bool write(const std::string& content, const std::string& filePath) { +bool write(const string& content, const string& filePath) { ofstream out(filePath, ios::out | ios::binary); - if (out) { - out << content; - out.close(); - return true; + if (!out) { + return false; } - return false; + out << content; + out.close(); + return true; } }; -- cgit v1.2.3