Skip to content

Instantly share code, notes, and snippets.

@xkyii
Created December 5, 2011 05:50
Show Gist options
  • Save xkyii/1432473 to your computer and use it in GitHub Desktop.
Save xkyii/1432473 to your computer and use it in GitHub Desktop.
read
std::ifstream in("some.file");
std::istreambuf_iterator<char> beg(in), end;
std::string str(beg, end);
// or
std::ifstream in("some.file");
std::ostringstream tmp;
tmp << in.rdbuf();
std::string str = tmp.str();
// 读取文件并按行遍历
std::ifstream in("some.file");
std::string line;
while(std::getline(in,line))
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment