我把这段代码写成一个函数,每次调用这个函数,我都想写入文件。但是这个函数只向文件写入一次。每当我从windows打开文件时,我发现只有一个单词写入文件。每次调用时如何连续写入文件?
/* Try and open a file for output */
QString outputFilename = "Results.txt";
QFile outputFile(outputFilename);
outputFile.open(QIODevice::WriteOnly);
/* Check it opened OK */
if(!outputFile.isOpen()){
qDebug() <<"- Error, unable to open" << outputFilename << "for output";
return ;
}
/* Point a QTextStream object at the file */
QTextStream outStream(&outputFile);
/* Write the line to the file */
outStream <<"\n"<< szTemp;//"Victory!\n";
/* Close the file */
outputFile.close();