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

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

PHP中文网
PHP中文网

认证0级讲师

répondre à tous(2)
黄舟

这样行不,不用数组用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

用getline函数就可以了,对于这个函数来说从文件读和从键盘读取是一样的了,读完一行处理了再到下一行,通过判断流状态结束读取就可以了

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!