User Tools

Site Tools


c_-_c_files:read_file_into_string

C - C++ Files - Read file into string

read_file_into_string.hpp

#pragma once
 
#include <string>
 
std::wstring read_file_into_wstring(std::string filename);
std::string read_file_into_string(std::string filename);

read_file_into_string.cpp

#include "read_file_into_string.hpp"
#include <sstream>
#include <fstream>
 
std::wstring read_file_into_wstring(std::string filename)
{
  std::wostringstream stream;
  stream << std::wifstream(filename).rdbuf();
 
  return stream.str();
}
 
 
std::string read_file_into_string(std::string filename)
{
  std::ostringstream stream;
  stream << std::ifstream(filename).rdbuf();
 
  return stream.str();
}

References

c_-_c_files/read_file_into_string.txt · Last modified: 2021/04/28 10:21 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki