读取txt文件,存入数组

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Discoverhfub/article/details/102498477
#include <iostream>
#include <fstream>
  
using namespace std;
  
const int ROW = 27;
const int VOL = 30;
  
int main(){
    double d[ROW][VOL];
    ifstream in("D:\\data.txt");//打开文件
    //读数据。。
    for(int i = 0; i < ROW; ++i){
        for(int j = 0; j < VOL; ++j){
            in >> d[i][j];
        }
    }
    in.close();//关闭文件
    //输出结果
    for(int i = 0; i < ROW; ++i){
        for(int j = 0; j < VOL; ++j){
            cout<<d[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Discoverhfub/article/details/102498477