恩恩,看过了。 DataStream 会加入一些其他字符。。。数字好像也是*来表示
明白了,谢谢. 还有两个个疑惑
QFile file("D:/Personal/Desktop/1.txt");
file.open(QIODevice::ReadOnly);
QTextStream xx(&file);
QString s,k;
xx>>s;//只能输出一行
这里xx>>s 是只能输出一行么?然后QDataStream 流利用 >>输出时,只能按照输入的
数据格式的顺序,一个个输出是么? 2.
想问一下,所以读取
一般的txt文件利用QdataStream是
没办法实现么? 个人感觉是这样
(当然如果是利用QDataStream 写一个txt文件,再利用DATAStream读取该txt文件肯定是可以的吧,
代码测试:
- void MainWindow::on_pushButton_3_clicked()
- {
- QFile file("[color=#ff0000]file.txt[/color]");
- file.open(QIODevice::WriteOnly);
- QDataStream out(&file); // we will serialize the data into the file
- out << QString("the answer is"); // serialize a string
- out << (qint32)42;
- out << QString("hello world");
- file.close();
- file.open(QIODevice::ReadOnly);
- QDataStream in(&file); // read the data serialized from the file
- QString str,str1;
- qint32 a;
- in>>str;
- qDebug()<<str;
- in>>a;
- qDebug()<<a;
- in>>str1;
- qDebug()<<str1;
- }
)
不知道意思表述的清不清楚,还麻烦您帮忙讲解一下。 前面说的已经收获很多非常感谢。