编程语言
首页 > 编程语言> > C++ 快速读取大文件

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";

 

标签:std,文件,读取,clock,buf,ios,C++,objpath,fin
来源: https://www.cnblogs.com/unrealCat/p/16518446.html