当前位置:网站首页>Simple read / write verification of qdatastream
Simple read / write verification of qdatastream
2022-07-01 05:06:00 【Autodesk_ Glodon】
The purpose is to write binary files and read contents :
#include <QApplication>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile aFile1("file.dat");
if (!(aFile1.open(QIODevice::WriteOnly)))// Open file in write only mode
return -1;
QDataStream bStream(&aFile1);
bStream.setVersion(QDataStream::Qt_5_9);
// Write the total size information space in turn , File name size information space , file name
QString currentFileName = "abcdFile" ;
qint64 v1 = 0,v2 = 0;
bStream << qint64(v1) << qint64(v2) << currentFileName;
// Cursor returns to the beginning of the file qint64 Make changes
bStream.device()->seek(0);
v1 = 13548,v2 = 8;
bStream<< qint64(v1) << qint64(v2);
// This step is to refresh the file , Let the written document take effect
aFile1.flush();
aFile1.close();
// Read dat file
QFile aFile2("file.dat");
if (!(aFile2.open(QIODevice::ReadOnly)))// Open file in write only mode
return -1;
QDataStream aStream(&aFile2);
aStream.setVersion(QDataStream::Qt_5_9);
qint64 v3 = 0,v4 = 0;
aStream >> v3 >> v4 >> currentFileName;// Reading data , Deposit in tem and str
qDebug() << v3 << v4 << currentFileName ;// Print it out and see the result
aFile2.close();
return a.exec();
}
边栏推荐
- Leetcode316- remove duplicate letters - stack - greedy - string
- 如何开始学剪辑?零基础详细解析
- STM32 光敏电阻传感器&两路AD采集
- Technology sharing | broadcast function design in integrated dispatching
- [daily question in summer] Luogu p5740 [deep foundation 7. Example 9] the best student
- STM32扩展版 按键扫描
- Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
- LeetCode_53(最大子数组和)
- Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
- AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
猜你喜欢

LeetCode316-去除重复字母-栈-贪心-字符串

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

分布式事务-解决方案

Detailed explanation of distributed global unique ID solution

Go learning notes (5) basic types and declarations (4)

无器械健身

工业导电滑环的应用

每日一题-LeetCode1175-质数排列-数学

Leetcode316- remove duplicate letters - stack - greedy - string

Principle, technology and implementation scheme of data consistency in distributed database
随机推荐
Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
[FTP] the solution to "227 entering passive mode" during FTP connection
Use of STM32 expansion board temperature sensor and temperature humidity sensor
导电滑环使用的注意事项
Solution: drag the Xib control to the code file, and an error setvalue:forundefined key:this class is not key value coding compliant for the key is reported
对象的序列化与反序列化
【暑期每日一题】洛谷 P2637 第一次,第二次,成交!
Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
[daily question in summer] Luogu p7222 [rc-04] informatics competition
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
【暑期每日一題】洛穀 P1568 賽跑
字符输入流与字符输出流
积分商城游戏能够给商家带来什么?怎么搭建积分商城?
AcWing 886. Finding combinatorial number II (pretreatment factorial)
AcWing 887. Finding combinatorial number III (Lucas theorem)
Thread safety issues
複制寶貝提示材質不能為空,如何解决?
【暑期每日一题】洛谷 P1568 赛跑
【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)