[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>()));
}

 

posted @ 2017-03-13 17:15  Tigmer  阅读(230)  评论(0)    收藏  举报