• 3623阅读
  • 0回复

文档输出~~~ [复制链接]

上一主题 下一主题
离线yangfanxing
 
只看楼主 倒序阅读 楼主  发表于: 2009-08-24
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
code
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <QFile>
#include <QTextSTream>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
    QFile file("data.txt");
//    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    if (!file.open(QIODevice::Text))
    {
        cerr << "Cannot open file for writing:"
        << qPrintable(file.errorString()) << endl;
        return false;
    }
    QTextStream out(&file);
    out << "name\tscore" << endl;
    out << "justin\t" << 95 << endl;
    out << "momor\t" << 93 << endl;
    out << "minnie\t" << 93 << endl;
    out << "mimi\t" << 93 << endl;
//    out << hex << 12345 << endl;
//                    //OK
    file.close();
    QTextStream in(&file);
    QString str1, str2;
    in >> str1 >> str2;
    cout << qPrintable(str1) << endl;
    cout << qPrintable(str2) << endl;
    return true;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在“//OK”以前的写入文档是可以的,想把刚写入的东西读出,以下怎么写???
该怎么改?

错误提示:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QIODevice::open: File access not specified
Cannot open file for writing:Unknown error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
请赐教~~~
PHPWind好恶心。。。不想看这种界面。。。
快速回复
限100 字节
 
上一个 下一个