当前位置:网站首页>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();
}
边栏推荐
- 解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
- Buffer stream and transform stream
- Oracle views the creation time of the tablespace in the database
- [hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
- 洗个冷水澡吧
- Go learning notes (5) basic types and declarations (4)
- STM32 photoresistor sensor & two channel AD acquisition
- 分布式事务-解决方案
- 1076 Forwards on Weibo
- AcWing 886. Finding combinatorial number II (pretreatment factorial)
猜你喜欢
STM32 expansion board digital tube display
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
Leetcode1497- check whether array pairs can be divided by K - array - hash table - count
Manually implement a simple stack
Basic skeleton of neural network nn Use of moudle
分布式架构系统拆分原则、需求、微服务拆分步骤
Oracle views the creation time of the tablespace in the database
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
Common methods in transforms
Leetcode522- longest special sequence ii- hash table - String - double pointer
随机推荐
[hard ten treasures] - 1 [basic knowledge] classification of power supply
STM32扩展板 温度传感器和温湿度传感器的使用
How to use common datasets in pytorch
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
複制寶貝提示材質不能為空,如何解决?
C read / write application configuration file app exe. Config and display it on the interface
Go learning notes (5) basic types and declarations (4)
Take a cold bath
分布式事务-解决方案
Character input stream and character output stream
Basic skeleton of neural network nn Use of moudle
Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
STM32 光敏电阻传感器&两路AD采集
Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
Pytoch (II) -- activation function, loss function and its gradient
AcWing 887. Finding combinatorial number III (Lucas theorem)
线程类的几大创建方法