轨迹信息传递
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
#include <stdlib.h>
#include <sstream>
using std::string;
using std::vector;
using namespace std;
void traj_out(string* path,vector<vector<double>> &temp_vector)
{
cout<<"*************************************************************"<<endl;
cout<<"文件的写操作"<<endl;
vector<vector<double>> out_vector;
out_vector=temp_vector;
ofstream outfile;
string temp;
for (vector<double>::size_type i=0;i!=(out_vector.size());i++)
{
cout<<"第"<<i<<"的值是:"<<endl<<" { ";
for(int j=0;j<6;j++)
{
cout << out_vector[i][j] << ", " << endl;
}
cout <<"} . " << endl;
}
outfile.open(*path);
for (vector<double>::size_type i=0;i!=(out_vector.size());i++)
{
string message;
for(int j=0;j<6;j++)
{
cout << out_vector[i][j] << ", " << endl;
temp = to_string(out_vector[i][j]);
message.append(temp);
message.append(" ");
}
outfile<<message<<endl;
}
outfile.close();
}
void traj_in(string *path)
{
ifstream infile;
vector<vector<double>> data_vector;
infile.open(*path);
string indata;
double temp;
if(!infile)
{
cout<<"读入文件不存在"<<endl;
}
if (infile.is_open())
{
int line = 1;
while (infile.good()&&!infile.eof())
{
vector<double> group;
cout << " line : " << line << endl;
for(int i =0;i<6;i++)
{
if(infile.good()&&!infile.eof())
{
infile>>indata;
istringstream strstream(indata);
strstream>>temp;
cout << temp <<endl;
}
else
{
cout<<"read file finished " << endl;
break;
}
group.push_back(temp);
}
cout << endl;
cout << "group size : " << group.size() <<endl;
line = line+1;
if(group.size()==6)
{
data_vector.push_back(group);
cout << "datavector size: "<< data_vector.size() <<endl;
}
else break;
}
}
infile.close();
for (vector<int>::size_type i=0;i!=(data_vector.size());i++)
{
for(int j =0;j<6;j++)
{
cout<<"line "<<i+1<<" "<< j+1 << " 项的值是:"<<data_vector[i][j]<<endl;
}
}
}
int main()
{
string path = "/home/wcz/QT/output_traj_test/data2";
vector<vector<double>> temp_vector = {{1,2,3,4,5,6},
{1.1,2.2,3.3,4.4,5.5,6.6}
};
traj_out(&path,temp_vector);
traj_in(&path);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)