1515#include < thread>
1616#include < cstdint>
1717#include < unistd.h>
18+ #include < streambuf>
1819
1920// ---------------------------------------------------------------------
2021
@@ -282,7 +283,7 @@ bool WSJCppCore::makeDir(const std::string &sDirname) {
282283
283284bool WSJCppCore::writeFile (const std::string &sFilename , const std::string &sContent ) {
284285
285- std::ofstream f (sFilename , std::ios::out );
286+ std::ofstream f (sFilename , std::ifstream::in );
286287 if (!f) {
287288 std::cout << " FAILED could not create file to wtite " << sFilename << std::endl;
288289 return false ;
@@ -295,6 +296,24 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const std::string &sCon
295296
296297// ---------------------------------------------------------------------
297298
299+ bool WSJCppCore::readTextFile (const std::string &sFilename , std::string &sContent ) {
300+
301+ std::ifstream f (sFilename );
302+ if (!f) {
303+ std::cout << " FAILED could not open file to read " << sFilename << std::endl;
304+ return false ;
305+ }
306+
307+ sContent = std::string (
308+ (std::istreambuf_iterator<char >(f)),
309+ std::istreambuf_iterator<char >()
310+ );
311+
312+ return true ;
313+ }
314+
315+ // ---------------------------------------------------------------------
316+
298317bool WSJCppCore::writeFile (const std::string &sFilename , const char *pBuffer, const int nBufferSize) {
299318 std::ofstream f (sFilename , std::ios::out | std::ios::binary);
300319 if (!f) {
@@ -307,6 +326,7 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const char *pBuffer, co
307326}
308327
309328
329+
310330// ---------------------------------------------------------------------
311331
312332std::string& WSJCppCore::ltrim (std::string& str, const std::string& chars) {
0 commit comments