[C++]普通文本文件最佳读取方式
#include <string> #include <fstream> #include <streambuf> inline std::string loadFileEx(const char* path) { setlocale(LC_ALL,"Chinese-simplified");//设置环境中文 std::ifstream ifs(path); setlocale(LC_ALL,"C");//还原环境 return std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); }
浙公网安备 33010602011771号