Ofstream写文件

来源:互联网 发布:mysql端口的作用 编辑:程序博客网 时间:2024/06/14 06:38
#include <fstream>#include "iomanip"std::vector<double> vecSensorYcoordinate,vecSensorXcoordinate;//保存到txtvoid SaveToTXT(std::string m_outfilename){if (vecSensorYcoordinate.size() != vecSensorXcoordinate.size()){QMessageBox::critical(nullptr, "错误", ("解析数据的结果X和y的数量不匹配!"));return;}std::ofstream outfile;setlocale(LC_ALL, "Chinese-simplified");outfile.open(m_outfilename.c_str(), std::ios::out);setlocale(LC_ALL, "C");if (!outfile.is_open()){QMessageBox::critical(nullptr, "错误", ("信息存盘失败,请检查文件路径是否存在"));return;}outfile << "x" << "" << "y" << "\n";for (int i = 0; i < vecSensorXcoordinate.size(); i++){outfile << std::setiosflags(std::ios::fixed);outfile << std::setprecision(8);outfile << vecSensorXcoordinate[i] << "" << vecSensorYcoordinate[i] << "\n";}outfile.close();}