|
@@ -1,4 +1,5 @@
|
|
|
#include <algorithm>
|
|
|
+#include <fstream>
|
|
|
#include <stdarg.h>
|
|
|
#include "strutil.h"
|
|
|
|
|
@@ -173,3 +174,33 @@ std::string strFormatByteSize(uint64_t s, unsigned int dec)
|
|
|
|
|
|
return szBuf;
|
|
|
}
|
|
|
+
|
|
|
+//////////////////////////////////////////////////////////////////////////////////
|
|
|
+// readFile
|
|
|
+
|
|
|
+bool readFile(const char *pszFilePath, std::string &str)
|
|
|
+{
|
|
|
+ std::ifstream stm(pszFilePath);
|
|
|
+ bool bGood = stm.good();
|
|
|
+
|
|
|
+ if(bGood)
|
|
|
+ {
|
|
|
+ stm.seekg(0, std::ios::end);
|
|
|
+ str.reserve(stm.tellg());
|
|
|
+ stm.seekg(0, std::ios::beg);
|
|
|
+ str.assign((std::istreambuf_iterator<char>(stm)), std::istreambuf_iterator<char>());
|
|
|
+ }
|
|
|
+
|
|
|
+ return bGood;
|
|
|
+}
|
|
|
+
|
|
|
+//////////////////////////////////////////////////////////////////////////////////
|
|
|
+// writeFile
|
|
|
+
|
|
|
+bool writeFile(const char *pszFilePath, const std::string &str)
|
|
|
+{
|
|
|
+ std::ofstream stm(pszFilePath);
|
|
|
+ stm << str;
|
|
|
+ stm.close();
|
|
|
+ return true;
|
|
|
+}
|