C C++ txt文本写入与读取

本文介绍如何使用C++和C语言对两种不同格式的txt文件进行读取和写入操作。第一种格式包含编号、x、y、z四个数据项,第二种格式涉及id和坐标数据。示例代码展示了具体的文件处理方法。
摘要由CSDN通过智能技术生成

文本格式1:
#编号 x y z(以空格隔开)
00000 41 18467 6334
00001 26500 19169 15724
00002 11478 29358 26962
00003 24464 5705 28145
00004 23281 16827 9961
00005 491 2995 11942
00006 4827 5436 32391
00007 14604 3902 153
00008 292 12382 17421
00009 18716 19718 19895
####################################
文本格式2:
#id0 x0 y0 id1 x1 y1 id2 x2 y2 (以空格隔开)
0 18467 41 1 26500 6334 2 15724 19169
1 29358 11478 2 24464 26962 3 28145 5705
2 16827 23281 3 491 9961 4 11942 2995
3 5436 4827 4 14604 32391 5 153 3902
4 12382 292 5 18716 17421 6 19895 19718
5 21726 5447 6 11538 14771 7 19912 1869
6 26299 25667 7 9894 17035 8 23811 28703
7 30333 31322 8 4664 17673 9 7711 15141
8 6868 28253 9 27644 25547 10 32757 32662
9 12859 20037 10 9741 8723 11 778 27529

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<fstream> //iftsream, ofstream
#include<sstream> //streamstring
#include<iomanip> //setw, setfill
#include<ctime> //rand
#include<vector>
using namespace std;

class mPoint
{
   
public:
	mPoint( int id, int x, int y) :m_id(id), m_x(x), m_y(y) {
   }
public:
	int m_id;
	int m_x;
	int m_y;
};

void WriteTxt_cpp(string txt_path); //c++风格写入,文本格式1
void ReadTxt_cpp(string txt_path); //c++风格读取,文本格式1

void WriteTxt_cpp_2(string txt_path); //c++风格写入,文本格式2
void ReadTxt_cpp_2(string txt_path); //c++风格读取,文本格式2

void WriteTxt_c(string txt_path); //c风格写入,文本格式1
void ReadTxt_c(string txt_path); //c风格读取,文本格式1

int main()
{
   
	string txt_path = "./xyz.txt";

	/*WriteTxt_cpp(txt_path);
	ReadTxt_cpp(txt_path);*/

	WriteTxt_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值