Created
December 1, 2014 02:58
-
-
Save kbinani/01d4d609c5bb82324862 to your computer and use it in GitHub Desktop.
PHP's file_get_contents function in C++
This file contains 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> | |
inline std::string file_get_contents(std::string const& path) | |
{ | |
return (std::stringstream() << std::ifstream(path).rdbuf()).str(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this wouldn't compile for me, giving me
and adding
#include <sstream>
gave me:but changing it to
compiled just fine :)
ps, i think std::ostringstream is a better fit, and that also compiles for me. (iirc ostringstream is slightly less versatile but faster than stringstream) soo