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

来源:互联网 发布:linux top 查看进程 编辑:程序博客网 时间:2024/05/22 03:21

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


阅读全文
0 0