15
15
#include < thread>
16
16
#include < cstdint>
17
17
#include < unistd.h>
18
+ #include < streambuf>
18
19
19
20
// ---------------------------------------------------------------------
20
21
@@ -282,7 +283,7 @@ bool WSJCppCore::makeDir(const std::string &sDirname) {
282
283
283
284
bool WSJCppCore::writeFile (const std::string &sFilename , const std::string &sContent ) {
284
285
285
- std::ofstream f (sFilename , std::ios::out );
286
+ std::ofstream f (sFilename , std::ifstream::in );
286
287
if (!f) {
287
288
std::cout << " FAILED could not create file to wtite " << sFilename << std::endl;
288
289
return false ;
@@ -295,6 +296,24 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const std::string &sCon
295
296
296
297
// ---------------------------------------------------------------------
297
298
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
+
298
317
bool WSJCppCore::writeFile (const std::string &sFilename , const char *pBuffer, const int nBufferSize) {
299
318
std::ofstream f (sFilename , std::ios::out | std::ios::binary);
300
319
if (!f) {
@@ -307,6 +326,7 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const char *pBuffer, co
307
326
}
308
327
309
328
329
+
310
330
// ---------------------------------------------------------------------
311
331
312
332
std::string& WSJCppCore::ltrim (std::string& str, const std::string& chars) {
0 commit comments