c++读取整个txt文件三种方式
1.按行读取
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::ifstream;
using std::ofstream;
using std::string;
using std::vector;
using std::cerr;
void test()
{
ifstream ifs("china_daily.txt"); //读取文件
if(!ifs.good())
{
cerr << "ifstream open file error!\n";
return;
}
string line;
vector<string> lines;