c++ 读文本文件

1. 

 std::ifstream t("example.txt");

    std::string str((std::istreambuf_iterator<char>(t)),

                    std::istreambuf_iterator<char>());

2

void readfile(const std::string &filepath,std::string &buffer){

    std::ifstream fin(filepath.c_str());

    getline(fin, buffer, char(-1));

    fin.close();

}

3

void readfile(const std::string &filepath,std::string &buffer){

    std::ifstream fin(filepath.c_str());

    stringstream strStream;

    strStream << fin.rdbuf();

    buffer= strStream.str();

    fin.close();

}

原文地址:https://www.cnblogs.com/anjsxz/p/3731477.html