当前位置:网站首页>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();
}
边栏推荐
- C read / write application configuration file app exe. Config and display it on the interface
- 【FTP】FTP常用命令,持续更新中……
- AcWing 884. Gauss elimination for solving XOR linear equations
- AssertionError assert I.ndim == 4 and I.shape[1] == 3
- Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
- Some tools that research dogs may need
- [FTP] common FTP commands, updating continuously
- Global and Chinese markets for soft ferrite cores 2022-2028: Research Report on technology, participants, trends, market size and share
- FileOutPutStream
- LeetCode_58(最后一个单词的长度)
猜你喜欢

Principle, technology and implementation scheme of data consistency in distributed database

Manually implement a simple stack

手动实现一个简单的栈

Common methods in transforms

Basic skeleton of neural network nn Use of moudle

Fitness without equipment

分布式数据库数据一致性的原理、与技术实现方案

Pytoch (III) -- function optimization
![[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array](/img/22/606ff1e8dad3d5896b32d2146b0477.jpg)
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array

Distributed architecture system splitting principles, requirements and microservice splitting steps
随机推荐
Go learning notes (5) basic types and declarations (4)
STM32 expansion board digital tube display
AcWing 889. 01 sequence satisfying the condition (Cartland number)
【暑期每日一题】洛谷 P2026 求一次函数解析式
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array
导电滑环短路的原因以及应对措施
Pytoch (II) -- activation function, loss function and its gradient
FileOutPutStream
LeetCode_ 58 (length of last word)
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
How to start learning editing? Detailed analysis of zero basis
Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
HCIP Day13
技术分享| 融合调度中的广播功能设计
LeetCode_28(实现 strStr())
Leetcode522- longest special sequence ii- hash table - String - double pointer
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply
AcWing 887. Finding combinatorial number III (Lucas theorem)