Ofstream写文件

#include 
#include "iomanip"

std::vector vecSensorYcoordinate,vecSensorXcoordinate;
//保存到txt
void 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();
}

你可能感兴趣的:(Ofstream写文件)