文件流infile读取数据

来源:互联网 发布:pve云裳数据面板 编辑:程序博客网 时间:2024/05/16 19:32
//读取文件数据#include <iostream>#include <string>#include <fstream>using namespace std;int main(){    string b[100];    string file_path = "D:\\P1.txt";    //cout << file << endl;    ifstream infile;    infile.open(file_path);    if (!infile.is_open())    {        cout << "无法打开文件" << endl;        exit(0);    }    /*    string str;    infile >> str;    cout << str << endl;    infile >> str;    cout << str << endl;    */    int i = 0;    while (infile >> b[i]){        i++;    }    for (int j = 0; j < i; j++){        cout << b[j] << endl;    }    infile.close();}
阅读全文
0 0
原创粉丝点击