当前位置:网站首页>Day12QFile2021-09-27
Day12QFile2021-09-27
2022-06-22 02:44:00 【Morning and evening rain】
QFile—— File operations
Qt The file operation of is very simple ,Qt Provided in the QIODevice Class as all I/O Equipment foundation interface , by IO Equipment such as QFile Provides an abstract interface .QFile Is a readable and writable text file 、 Binary 、 as well as qt Of resource files IO equipment . Before accessing a device , Need to use open() Function to open the device , And the correct opening mode must be established . Use write()、putchar Method write ,read(),readline()、readAll() Method read , with QTextStream or QDataStream Use a combination of , More convenient . So after the operation ends , You should use close() Method to close the file , Keep good habits .
Case study :
Output txt file , Separate use write and QTextStream There are two ways to write .
1. stay .cpp or .h Add header file to
#include <QFile>
#include <QTextStream>
2.cpp The code in the file is as follows , First, construct the file object , Create a file by parameter name , And then to append Way to open a file , Use QTextStream Class to write “ written words ”, Use write() Function writes a string , Last call close() Close file .
QFile file("Day12.txt");
file.open(QIODevice::Append);
// Use QTextStream write file
QTextStream tsm(&file);
QString str = " Please believe that , All accumulation has its specific value !\r\n";
tsm<<str<<"Designed by Jack chen";
file.write("Day12\r\n");
file.close();
3. Running effect : Generated under the build directory Day12.txt file , The contents are as follows :
边栏推荐
- Dernière publication: neo4j Graph Data Science GDS 2.0 et aurads ga
- C # judge whether the application is started and displayed
- Unity3d post process volume profile
- Relative references must start with either “/“, “./“, or “../“.
- 2022钎焊考试模拟100题及答案
- [1. quick sort]
- [9. submatrix sum]
- Write your own kubernetes controller
- import和require在浏览器和node环境下的实现差异
- Pytorch visualization
猜你喜欢

Development of power plant compliance test system with LabVIEW

C++ primer Chapter 2 summary of variables and basic types

With the acceleration of industry wide digital transformation, what kind of storage will be more popular?

Li Kou today's question 1108 IP address invalidation

Wechat applet film and television comment exchange platform system graduation design (2) applet function

Must the database primary key be self incremented? What scenarios do not suggest self augmentation?

C ++ Primer 第2章 变量和基本类型 总结

银联支付 返回商户 Nignx post请求405

Graphacademy course explanation: Fundamentals of neo4j graph data science

Wechat applet film and television review and exchange platform system graduation design completion (7) Interim inspection report
随机推荐
关于PMP考试,你想知道的知识都在这里了
[1. quick sort]
GraphAcademy 课程讲解:《Neo4j 图数据科学简介》
【2. 归并排序】
Relative references must start with either “/“, “./“, or “../“.
Live broadcast on June 22 | zhanzhihui, South China Institute of Technology: evolutionary computing for expensive optimization
微软 IE 浏览器于 6 月 15 日被永久关闭
Annual special analysis of China Mobile Banking in 2022
EMC辐射发射整改-原理案例分析
How to apply PMP project management knowledge?
最新发布:Neo4j 图数据科学 GDS 2.0 和 AuraDS GA
PMP pre exam guide on June 25, you need to do these well
Ioerror: no translation files found for default language zh cn Solutions for
Flash back when GoLand starts
fatal error: png++/png.hpp: 没有那个文件或目录
Must the database primary key be self incremented? What scenarios do not suggest self augmentation?
Starting from the classification of database, I understand the graph database
Latest release: neo4j figure data science GDS 2.0 and aurads GA
Anaconda historical version download
[Chapter 26 medical impact segmentation system based on minimum error method and region growth -- matlab deep learning practical GUI project]