C++进行TXT坐标文件读写

前言

使用C++进行坐标文件读写在日常中是一个非常常见的功能,每次使用的时候总是需要查一下,这次找了个时间写下来记录一下。详细的使用方法可以从这里学习:https://www.runoob.com/cplusplus/cpp-files-streams.html

txt文件读取

首先我们需要读取的文件在txt中显示如下:
在这里插入图片描述
读取代码:

//头文件
#include <iostream>
#include <fstream>
using namespace std;
//读取文件
void readTXT(string blhTxtName)
{
	ifstream infile(blhTxtName);
	if (!infile)
	{
		cout << "error!" << endl;
		return;
	}
	double x, y, z;
	while (infile>>x>>y>>z)
	{
		cout << x << " " << y << " " << z << endl;
	}
	infile.close();
}

保存文件到txt

//保存XYZ TXT
void saveTXT(string xyzTxtName, vector<MyXYZ> inDataVec)
{
	ofstream outFile(xyzTxtName);
	outFile << fixed;//防止以数值以科学计数法保存
	for (auto t : inDataVec)
	{
		outFile << t.x << " " << t.y << " " << t.z << endl;
	}
	outFile.close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值