永发信息网

标准C++中怎样读取整个文本文件到string中

答案:1  悬赏:0  手机版
解决时间 2021-03-10 15:51
  • 提问者网友:最美的风景
  • 2021-03-10 06:10
标准C++中怎样读取整个文本文件到string中
最佳答案
  • 五星知识达人网友:行路难
  • 2021-03-10 06:59
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main() {
ifstream fin;
string temp[20],total = "";
char filename[60];
int i = 0;
cout << " Enter the reference file: \n";
cin.getline(filename,'\n');
fin.open(filename,ios::in);
while(fin.good() && i < 20){
getline(fin,temp[i]);
total += temp[i]; // += 已被重载
cout << temp[i] << endl;
i++;
}
//
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯