c_-_c_files:read_file_into_string
This is an old revision of the document!
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 ===== <code 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.1619601674.txt.gz · Last modified: 2021/04/28 09:21 by peter