seekp()和seekg()函数简单的应用
来源:互联网 发布:js移除数组中某个元素 编辑:程序博客网 时间:2024/06/01 12:11
#include<iostream>
#include<fstream>
using namespace std;
class Stu
{
public:
char name[10];
int id;
Stu()
{
strcpy_s(name, "Z");
id = 0;
}
Stu(char *n, int i)
{
strcpy_s(name, n);
id = i;
}
};
int main()
{
ofstream out1;
out1.open("d.dat", ios::binary);
Stu s1[3];
s1[0] = { "A", 10 };
s1[1] = { "B", 20 };
s1[2] = { "C", 30 };
for (int i = 0; i < 3; i++)
{
out1.write((char*)&s1[i], sizeof(s1[i]));//保存到磁盘中
}
out1.close();
out1.open("d.dat", ios::binary);
out1.seekp(2 * sizeof(s1[0]), ios::cur);//将磁盘文件指针设置到s1[2]的位置
Stu ss("lin", 20);
out1.write((char*)&ss, sizeof(ss));//修改s1[2]的值
out1.close();
ifstream in1;
Stu p;
in1.open("d.dat", ios::binary);
in1.seekg(2*sizeof(s1[0]), ios::cur);//将文件指针设置到s1[2]的位置
in1.read((char *)&p, sizeof(s1[1]));//读取s1[2]的值,检查修改后是否成功
cout << "name:" << p.name <<'\t'<< "id:" << p.id << endl;
in1.close();
return 0;
}
- seekp()和seekg()函数简单的应用
- tellg,tellp,seekp,seekg函数
- tellg,tellp,seekp,seekg函数
- tellg,tellp,seekp,seekg函数
- C++里的seekg(),tellg(),seekp(),tellp()函数
- 奇怪的seekg()还有seekp()
- c++ fstream中seekg()和seekp()的用法
- C++ fstream中seekg()和seekp()的用法
- c++ fstream中seekg()和seekp()的用法
- 文件操作 tellg,tellp,seekp,seekg函数
- fstream 里的 seekg() seekp() 区分记忆
- 在C++文件读写操作中,seekg()和seekp()是一样的功能
- c++ seekp() seekg()
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解 .
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解
- 本地如何搭建IPv6环境测试你的APP
- 430_AD采样不准确问题
- poj 1330 Nearest Common Ancestors lca rmq在线算法
- qt4连接mysql(2)
- 宏与内联
- seekp()和seekg()函数简单的应用
- 百度定位
- java的继承关系中,构造方法调用问题
- linux 静态与动态ip设置
- Docker 入门教程(九)
- synchronized 修饰在 static方法和 非static方法的区别
- Android 屏幕适配方案(百分比)
- Java中的Random()函数
- 怎么实现ZBrush中复数对象的快速运用