2

我有以下代码,我正在尝试写入文件。调用时,在目录中创建文件并for-loop输入。in 的值QVector<int> program也存在并且在 中可见qDebug()。但是,在我关闭文件和窗口后,我在计算机上检查了文件,它完全是空的。我已经检查了 StackOverflow 和 Qt 论坛,但还没有找到解决方案。

    QString save_file = "C:/Users/MARVIN/Documents/Saddleback College/2015/Fall/CS3A/Semester Project/Emulator/hello.txt";

    QFile file(save_file);

    if(file.open(QFile::WriteOnly))
    {
        QTextStream out(&save_file);

        out << "hello" << endl;

        for(int i = 0; i < 100; i++)
        {
            out << program[i] << endl;
            qDebug() << program[i] << endl;
        }

        file.close();
        this->close();
    }
4

1 回答 1

3

你的问题:

QTextStream out(&save_file);

应该

QTextStream out(&file);
于 2015-11-09T06:22:49.473 回答