struct data {
double x_axis;
double y_axis;
double z_axis;
double relativity;
};
Data Min_Point;
vector<double> distances;
vector<Data> Point_Main_File;
int main(){
vector<Data> Points_myfile, Points_original_file;
vector<string> Strings;
ifstream fileReader;
fileReader.open("myfile.ply", ios::in);
if(fileReader.is_open()){
string str = "";
int count = 0;
while(!fileReader.eof()){
if(count < 31){
getline(fileReader, str, '\n');
Strings.push_back(str);
cout << str << endl;
count++;
}
else{
double input = 0;
Data Point;
fileReader >> input;
if(input == 0)
break;
Point.x_axis = input;
fileReader >> input;
Point.y_axis = input;
fileReader >> input;
Point.z_axis = input;
fileReader >> input;
Point.relativity = input;
Points_myfile.push_back(Point);
cout << Point.x_axis << " " << Point.y_axis << " "<< Point.z_axis << " " << Point.relativity << endl;
}
}
fileReader.close();
}
else{
cout<<"File not Found"<<endl;
}
fileReader.open("original.ply", ios::in);
if(fileReader.is_open()){
string str = "";
int count = 0;
while(!fileReader.eof()){
if(count < 31){
getline(fileReader, str, '\n');
cout << str << endl;
count++;
}
else{
double input = 0;
Data Point;
fileReader >> input;
if(input == 0)
break;
Point.x_axis = input;
fileReader >> input;
Point.y_axis = input;
fileReader >> input;
Point.z_axis = input;
fileReader >> input;
Point.relativity = input;
Points_original_file.push_back(Point);
cout << Point.x_axis << " " << Point.y_axis << " " << Point.z_axis << " " << Point.relativity << endl;
}
}
fileReader.close();
}
else{
cout << "File not Found" << endl;
}
for(int iterate = 0; iterate < Points_original_file.size(); iterate++){
get_Minimum_Cartesian_Distance(Points_original_file.at(iterate), &Points_myfile);
}
cout<<endl<<endl;
ofstream outfile;
outfile.open("myfile.ply", ios::out);
if(outfile.is_open()){
for(int iterate = 0; iterate < Strings.size(); iterate++){
outfile << Strings.at(iterate) << endl;
}
int total_size = distances.size();
for(int index = 0; index < total_size; index++){
outfile << std::fixed << Point_Main_File.at(0).x_axis << " ";
outfile << std::fixed << Point_Main_File.at(0).y_axis << " ";
outfile << std::fixed << Point_Main_File.at(0).z_axis <<" ";
outfile << std::fixed << Point_Main_File.at(0).relativity << endl;
Point_Main_File.erase(Point_Main_File.begin());
distances.erase(distances.begin());
}
outfile.close();
}
else {
cout << "Cant Open File" << endl;
}
return 0;
}
我有一个程序,与第二个文件相比,它根据笛卡尔距离重新排列层文件中的行。但是这些值会自动取整,我不希望这样。例如,如果最初,我的行包含
9.832004 1.55884 1.4956 0.2224
重新排列文件时,将其写为
9.832000 1.55800 1.4895 0.0000
我也尝试过使用fixed(),但这没有帮助。如何停止此自动舍入/截断?
如果您的问题只是输出文件的重新排列(而不是计算的重新排列,则可以将输入值也保存为字符串,然后使用字符串重新排列输出文件。