Skip to content

Instantly share code, notes, and snippets.

@cztchoice
Last active March 24, 2018 07:30
Show Gist options
  • Save cztchoice/40d4d3f23183413b7470982fead59d41 to your computer and use it in GitHub Desktop.
Save cztchoice/40d4d3f23183413b7470982fead59d41 to your computer and use it in GitHub Desktop.
C++读取文件到string
std::ostringstream fileContentsStream;
fileContentsStream << std::ifstream("MyFile.txt").rdbuf();
std::string fileContents = fileContentsStream.str();
std::ifstream ifs("D:/quote/beforetidy.html");
std::string content((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment