C++将文件内容一次性读入内存

结合字符串流,将文件中的内容一次性读入内存,代码如下:

#include <string>
using std::ostringstream;
using std::ifstream;
using std::string;
std::string fileContent;
string strFileName="ServiceIpConfig.txt";//文件名字
fin.open(strFileName.c_str());
if (fin.is_open())
{
ostringstream temp;//字符串流,提供对于string对象的写的功能。
temp<<fin.rdbuf();//往字符串流中写
fileContent= temp.str();
fin.close();
}
上一篇:free命令常用参数详解


下一篇:shell编程系列23--shell操作数据库实战之mysql命令参数详解