首页 > 代码库 > 跟我一起学QT9:输入与输出

跟我一起学QT9:输入与输出

0.源代码下载

1. 二进制文件的读取和写入

https://github.com/leichaojian/qt/tree/master/readfile

2. 文本流的写入和读取

https://github.com/leichaojian/qt/tree/master/readtextfile


1. 二进制文件的读取和写入

1. 关键代码

//写入二进制文件
    QDataStream out(&file);
    out.setVersion(QDataStream::Qt_5_3);
    out << quint32(0x12345678) << image << map;
    file.close();

    //读取二进制文件
    QDataStream in(&outFile);
    in.setVersion(QDataStream::Qt_5_3);
    in >> value >> outImage >> outMap;



2. 程序调试状态下输出


2. 文本流的写入和读取

1. 关键代码

while (!inFileStream.atEnd()) {
        outFileStream << inFileStream.readLine() << endl;
    }
    outFileStream.seek(0);
    while (!outFileStream.atEnd()) {
        qDebug() << outFileStream.readLine();
    }



2. 程序输出

"hello"
"world"
"i"
"love"
"this"
"world"
"and"




跟我一起学QT9:输入与输出