欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++ 讀文件 將文件內(nèi)容讀入到字符串string中的方法

 更新時(shí)間:2018年07月13日 11:10:41   作者:奮斗_小伙  
今天小編就為大家分享一篇C++ 讀文件 將文件內(nèi)容讀入到字符串string中的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

如下所示:

#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
 
#include <stdlib.h>
using namespace std;
 
 
//從文件讀入到string里
string readFileIntoString(char * filename)
{
ifstream ifile(filename);
//將文件讀入到ostringstream對(duì)象buf中
ostringstream buf;
char ch;
while(buf&&ifile.get(ch))
buf.put(ch);
//返回與流對(duì)象buf關(guān)聯(lián)的字符串
return buf.str();
}
 
int main()
{
//文件名
char * fn="a.txt";
string str;
str=readFileIntoString(fn);
cout<<str<<endl;
system("pause");
 
}

以上這篇C++ 讀文件 將文件內(nèi)容讀入到字符串string中的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論