【发布时间】:2012-07-19 18:43:22
【问题描述】:
我正在尝试编写一个程序,该程序将创建一个文本文件并写入我从串行端口读取的字符流。我只是想了解如何让代码连续写入数据而不覆盖以前写入的数据,因为我需要它来保持发送的每个字符。我写了这段代码作为测试,但我不能让它连续写文本。它写一次然后停止。
#include <QFile>
#include <QTextStream>
int main() {
int test = 0;
while(test < 2){
QString filename = "Data.txt";
QFile file(filename);
if (file.open(QIODevice::ReadWrite)) {
QTextStream stream(&file);
stream << "one thing to test" << endl;
test++;
}
}
}
大家有什么建议吗?
-谢谢
【问题讨论】:
标签: c++ qt text serial-port