qt 文本流&数据流

        // 文本流
        QFile file("aaa.txt");
        file.open(QFileDevice::WriteOnly);
        QTextStream stream(&file);
        stream<<QString("hell oworld")<<123456;
        file.close();
        // 读取文本流
        file.open(QIODevice::ReadOnly|QIODevice::Text);
        stream.setAutoDetectUnicode(true);
        while(!stream.atEnd()){
            QString str = stream.readLine();
            qDebug()<<str;
        }
       // 数据流
          QFile file("bbb.txt");
          file.open(QIODevice::WriteOnly);
          QDataStream astrem(&file);
          astrem<<QString("hello world")<<123456;
          file.close();

          file.open(QIODevice::ReadOnly);
          QString str;
          int num;
          astrem>>str>>num;

          qDebug()<<str<<num;
          file.close();
上一篇:6.Z字形变换


下一篇:【VUE】【axios】天气查询小案例