问题描述
我想用c++读取文本文件,怎么每次只读取一行,然后将这一行放到数组中,再读下一行,依次类推。
问题解答
回答1:这样行不,不用数组用string
#include <iostream>#include <string>#include <fstream>#include <sstream>using namespace std;int main(){ string s; ifstream input('your file here'); while (getline(input, s));}回答2:
用getline函数就可以了,对于这个函数来说从文件读和从键盘读取是一样的了,读完一行处理了再到下一行,通过判断流状态结束读取就可以了