当前位置:网站首页>QDataStream的简单读写验证
QDataStream的简单读写验证
2022-07-01 05:06:00 【欧特克_Glodon】
目的是写入二进制文件和读取内容:
#include <QApplication>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile aFile1("file.dat");
if (!(aFile1.open(QIODevice::WriteOnly)))//用只写的方式打开文件
return -1;
QDataStream bStream(&aFile1);
bStream.setVersion(QDataStream::Qt_5_9);
//依次写入总大小信息空间,文件名大小信息空间,文件名
QString currentFileName = "abcdFile" ;
qint64 v1 = 0,v2 = 0;
bStream << qint64(v1) << qint64(v2) << currentFileName;
//游标回到文件最开始的地方对qint64进行修改
bStream.device()->seek(0);
v1 = 13548,v2 = 8;
bStream<< qint64(v1) << qint64(v2);
//这一步是刷新文件,让写进去的文件生效
aFile1.flush();
aFile1.close();
// 读取dat文件
QFile aFile2("file.dat");
if (!(aFile2.open(QIODevice::ReadOnly)))//用只写的方式打开文件
return -1;
QDataStream aStream(&aFile2);
aStream.setVersion(QDataStream::Qt_5_9);
qint64 v3 = 0,v4 = 0;
aStream >> v3 >> v4 >> currentFileName;//读取数据,存入tem和str
qDebug() << v3 << v4 << currentFileName ;//打印出来看看结果
aFile2.close();
return a.exec();
}
边栏推荐
- How to use common datasets in pytorch
- STM32 光敏电阻传感器&两路AD采集
- AcWing 885. Find the combination number I (recursive preprocessing)
- 【暑期每日一题】洛谷 P5886 Hello, 2020!
- FileInputStream
- 【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
- [NLP Li Hongyi] notes
- 液压滑环的特点讲解
- js解决浮点数相乘精度丢失问题
- Principle, technology and implementation scheme of data consistency in distributed database
猜你喜欢

Neural networks - use of maximum pooling

How to hide browser network IP address and modify IP internet access?

技术分享| 融合调度中的广播功能设计

STM32 光敏电阻传感器&两路AD采集

导电滑环使用的注意事项

手动实现一个简单的栈
![Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*
![[hard ten treasures] - 1 [basic knowledge] classification of power supply](/img/a8/f129c9d15ca6ed99db1dacfc750ead.png)
[hard ten treasures] - 1 [basic knowledge] classification of power supply

C read / write application configuration file app exe. Config and display it on the interface

PR 2021 quick start tutorial, learn about the and functions of the timeline panel
随机推荐
Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
Principle, technology and implementation scheme of data consistency in distributed database
导电滑环使用的注意事项
液压滑环的特点讲解
【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
导电滑环短路的原因以及应对措施
工业导电滑环的应用
Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
複制寶貝提示材質不能為空,如何解决?
[FTP] common FTP commands, updating continuously
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
每日一题-LeetCode1175-质数排列-数学
FileOutPutStream
Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode_ 53 (maximum subarray and)
Pytorch convolution operation
How to start learning editing? Detailed analysis of zero basis
Design experience of Meizhou clinical laboratory
AcWing 889. 01 sequence satisfying the condition (Cartland number)
字符输入流与字符输出流