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

}

posted @ 2014-05-16 09:29  anjsxz  阅读(157)  评论(0编辑  收藏  举报