Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.


//  filesystem/string_file.hpp  --------------------------------------------------------//

//  Copyright Beman Dawes 2015

//  Distributed under the Boost Software License, Version 1.0.
//  See

//  Library home page:


#include <string>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>

namespace boost
namespace filesystem
void save_string_file(const path& p, const std::string& str)
  ofstream file;
  file.exceptions(std::ofstream::failbit | std::ofstream::badbit);, std::ios_base::binary);
  file.write(str.c_str(), str.size());

void load_string_file(const path& p, std::string& str)
  ifstream file;
  file.exceptions(std::ifstream::failbit | std::ifstream::badbit);, std::ios_base::binary);
  std::size_t sz = static_cast<std::size_t>(file_size(p));
  str.resize(sz, '\0');[0], sz);
}  // namespace filesystem
}  // namespace boost

#endif  // include guard