Last active
March 1, 2021 21:06
-
-
Save blippy/3dc25269932fa6f8da003affd2a70e68 to your computer and use it in GitHub Desktop.
Slurp a file in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <fstream> | |
| #include <sstream> | |
| std::string slurp(const char *filename) | |
| { | |
| std::ifstream in; | |
| in.open(filename, std::ifstream::in | std::ifstream::binary); | |
| std::stringstream sstr; | |
| sstr << in.rdbuf(); | |
| in.close(); | |
| return sstr.str(); | |
| } |
What about files with different encodings like "UCS-2 BE BOM" or so?
Updated to include binary. It just slurps a file, it won't do any decoding to UTF-8 or anything like that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about files with different encodings like "UCS-2 BE BOM" or so?