Skip to content

Instantly share code, notes, and snippets.

@yenliangl
Created November 21, 2012 08:36
Show Gist options
  • Save yenliangl/4123824 to your computer and use it in GitHub Desktop.
Save yenliangl/4123824 to your computer and use it in GitHub Desktop.
Improving performance of ifstream in C++
std::ifstream file("test.txt", std::ios::in | std::ios::end);
std::size_t fileSize = file.tellg();
std::vector<char> buffer(fileSize);
file.seekg(0, std::ios::beg);
file.read(buffer.data(), fileSize);
std::string str(buffer.begin(), buffer.end());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment