QTextStream的使用
来源:互联网 发布:淘宝家居装修论坛网 编辑:程序博客网 时间:2024/05/13 19:57
#include <QCoreApplication>#include <QTextStream7gt;#include <QFile>#include <QDebug7gt;void write(){ QFile file("C:/Test/simple.txt"); if(file.open(QIODevice::WriteOnly | QIODevice::Text)) { // We're going to streaming text to the file QTextStream stream(&file); stream << "Debussy\n"; stream << "Rabel\n"; file.close(); qDebug() << "Writing finished"; }}void read(){ QFile file("C:/Test/simple.txt"); if(file.open(QIODevice::ReadOnly|QIODevice::Text)) { // We're going to streaming the file // to the QString QTextStream stream(&file); QString line; do { line = stream.readLine(); qDebug() << line; } while(!line.isNull()); file.close(); qDebug() << "Reading finished"; }}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); write(); read(); return a.exec();}
Output:
Writing finished"Debussy""Rabel"""Reading finished
It's also common to use QTextStream to read console input and write console output. QTextStream is locale aware, and will automatically decode standard input using the correct codec. Example:
QTextStream stream(stdin);QString line;do { line = stream.readLine();} while (!line.isNull());
0 0
- QTextStream的使用
- QTextStream的使用 读写文件
- QT ini配置文件的读写(使用QTextStream类)
- QTextStream
- QTextStream
- 使用QTextStream实现文本文件拷贝
- QFile和QTextStream配合使用
- QTextStream和QDataStream的区别
- QTextStream和QDataStream的区别
- QTextStream和QDataStream的区别
- Qt编程11:QTextStream文件输入输出以及字符串操作的简单使用
- Qt使用Qtextstream进行换行操作
- 中文使用ofstream/wfstream/qtextstream写入
- Qt对文件的操作,QTextStream
- PyQt的QTextStream类对文本的读写简要说明
- QTextStream类
- Qt模块化笔记之core——Input/Output文件操作-流QTextStream使用
- QTextStream 读取文件内容
- T001_UT001_0013
- HDU 3577 Fast Arrangement
- 徐汉彬:Web系统大规模并发——电商秒杀与抢购
- T001_UT001_0014
- 黑马学员《java环境配置》
- QTextStream的使用
- 9本Java程序员必读的书
- JSON知识复习
- T001_UT001_0015
- 黑马学员《String》
- 修改oracle 10g rac监听端口号为1523的步骤
- Git常用命令速查
- VB配置文件处理类
- LeetCode - Wildcard Matching