读取文件中所有的字符

最简洁的做法是用ios::rdbuf():

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

bool getFileStr(string filename, string str)
{
ifstream src(filename.c_str());
if(src.is_open())
{
str = src.rdbuf().str();
src.close();
return true;
}

retrun false;
} 
 

你可能感兴趣的:(ios,String)