您的位置:首页 > 编程语言 > C语言/C++

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

2017-08-22 17:12 891 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐