c++ 读文本文件

时间:2014-05-19 21:27:01   收藏:0   阅读:321

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

}

c++ 读文本文件,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!