我想用c++读取文本文件,怎么每次只读取一行,然后将这一行放到数组中,再读下一行,依次类推。
认证0级讲师
Is this okay? Instead of using an array, use 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)) ; }
Just use the getline function. For this function, reading from a file is the same as reading from the keyboard. After reading one line, process it and move on to the next line. Just end the reading by judging the stream status
Is this okay? Instead of using an array, use string
Just use the getline function. For this function, reading from a file is the same as reading from the keyboard. After reading one line, process it and move on to the next line. Just end the reading by judging the stream status