84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
我想用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