C++读取文本文件
PHP中文网
PHP中文网 2017-04-17 13:13:40
0
2
653

我想用c++读取文本文件,怎么每次只读取一行,然后将这一行放到数组中,再读下一行,依次类推。

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
黄舟

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))
        ;
}
Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template