C++ 快速读取大文件

方法一、

clock_t start = clock();
ifstream fin(objpath,std::ios::binary);

vector<char> buf(fin.seekg(0,std::ios::end).tellg());
fin.seekg(0,std::ios::beg).read(&buf[0],static_cast<std::streamsize>(buf.size()));

fin.close();
clock_t end = clock();
cout << "time:" << ((double)end-start)/CLOCKS_PER_SEC << "s\n";

方法二、

clock_t start = clock();
ifstream fin(objpath);

stringstream buf;
buf << fin.rdbuf();

fin.close();
clock_t end = clock();
cout << "time:" << ((double)end-start)/CLOCKS_PER_SEC << "s\n";

 

posted @ 2022-07-25 18:54  幻cat  阅读(453)  评论(0编辑  收藏  举报