123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include "file_contents_as_string.h"
- #include <fstream>
- #include <cstdio>
- #include <cassert>
- IGL_INLINE bool igl::file_contents_as_string(
- const std::string file_name,
- std::string & content)
- {
- std::ifstream ifs(file_name.c_str());
-
- if(!ifs.good())
- {
- fprintf(
- stderr,
- "IOError: file_contents_as_string() cannot open %s\n",
- file_name.c_str());
- return false;
- }
-
- content = std::string(
- (std::istreambuf_iterator<char>(ifs)),
- (std::istreambuf_iterator<char>()));
- return true;
- }
- IGL_INLINE std::string igl::file_contents_as_string(
- const std::string file_name)
- {
- std::string content;
- #ifndef NDEBUG
- bool ret =
- #endif
- file_contents_as_string(file_name,content);
- assert(ret && "file_contents_as_string failed to read string from file");
- return content;
- }
|