fstream:一行一行的读取文件数据

使用fstream一行行的读取文件数据。  Windows/Linux均测试通过。


一、代码
#include <iostream>
#include <fstream>
#include <string>
using namespace std;


int main(int argc, char*argv[])
{
	ifstream read_file;
	read_file.open("aaa.txt", ios::binary);

	string line;
	while(getline(read_file, line))
	{
		cout<<"line:"<<line.c_str()<<endl;
	}

	return 0;
}


二、文件与输出结果

2.1 文件:aaa.txt

fstream:一行一行的读取文件数据_第1张图片


2.2 输出结果

fstream:一行一行的读取文件数据_第2张图片

你可能感兴趣的:(fstream:一行一行的读取文件数据)