84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
我想用c++读取文本文件,怎么每次只读取一行,然后将这一行放到数组中,再读下一行,依次类推。
认证0级讲师
这样行不,不用数组用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)) ; }
用getline函数就可以了,对于这个函数来说从文件读和从键盘读取是一样的了,读完一行处理了再到下一行,通过判断流状态结束读取就可以了
这样行不,不用数组用string
用getline函数就可以了,对于这个函数来说从文件读和从键盘读取是一样的了,读完一行处理了再到下一行,通过判断流状态结束读取就可以了