C++快速读取大文件

#include 
#include 
#include 
#include 
#include 

using namespace std;

/**
 * 快速读取大文件
 * @return
 */
int main()
{
    clock_t start = clock();
    ifstream fin("d:\\1.txt", std::ios::binary);

    vector<char> buf(static_cast<unsigned int>(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";
    vector<char>::iterator it;
    for (it = buf.begin(); it != buf.end(); it++)
    {
        cout << *it << "";
    }
    cout << endl;
}

你可能感兴趣的:(C++快速读取大文件)