C++读取txt文本数据到vector

发布时间 2023-06-30 09:44:37作者: WEIWEI1095

//读取txt文本中的float数据(按行读取)
void read_txt_input(std::string path,std::vector &pydata){
std::ifstream infile;
infile.open(path);
float value;
if(!infile){
std::cout<<"file not found"<<endl;
exit(1);
}
while(infile>>value){
pydata.push_back(value);
}
infile.close();
}
//工作中修改tensor数据方式
std::vector py_y_output;
std::string path="";
read_txt_input(path,py_y_output);
int y_output_n = y_output->shape()[0];
int y_output_h = y_output->shape()[1];
int y_output_w = y_output->shape()[2];
int y_output_c = y_output->shape()[3];
for (int i=0;i<(y_output_ny_output_hy_output_w*y_output_c;i++)
{
y_output->mudata()[i]=
}
//
int main(){
std::vector py_data;
std::string path_py_data = "./test/py_data_"+std::to_string(k)+".txt";
read_txt_input(path_py_data,py_data);
return 0;
}