C++ 怎么依次读取多个TXT里面的数据,放到一个数组里面

C++ 怎么依次读取多个TXT里面的数据,放到一个数组里面


    int j_num_fea =0;
    std::string ss1;
    long int num_total_lines=0;
    long long int LINES[5];
    long long int start_lines=0;

    int row=9 ,col=8;

    float training_data[row][col-1];
    float lables[row];



    while(j_num_fea<1) {

        char szName[100] = {'\0'};

        sprintf(szName,          
              "../test_ws/txt_dataset/test_read/feature%d.txt",
                j_num_fea);


        LINES[j_num_fea]=CountLines(szName);
        cerr<<"The number of lines is :"<<LINES[j_num_fea]<<endl;
        cerr<<"The value of the szname is :"<<szName<<std::endl;

        ifstream fin(szName); //read the training dataset.


        for(int i=start_lines;i< start_lines+ LINES[j_num_fea] ;i++){
            for(int j=0;j<col;j++) {
                if(j<col-1){
                    fin >> training_data[i][j];
                    cerr<<"the number of the training data is :"<< training_data[i][j]<<endl;
                }else{
                    fin >> lables[i];//The training lables
                }
            }
        }
        fin.close();

        start_lines+=LINES[j_num_fea];
        cerr<<"The number of the start_lines is :"<<start_lines<<endl;
        j_num_fea++;

    }

    for(int i=0;i<9;i++){
        for(int j=0;j<7;j++){

          std::cout<<std::fixed<<training_data[i][j]<<" ";
        }
        std::cout<<std::endl;
        std::cout<<lables[i]<<std::endl;
    }




  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值