mwc*_*wcz 10 c++ qt qt4 qt-creator
我已经用Google搜索了这个错误,直到我脸红了,但是无法将任何结果与我的代码联系起来.这个错误通常是由于错误或缺少括号,父母等造成的.
自从我编写任何C++以来,这已经很长时间了,所以我可能会有一些明显的,愚蠢的事情.
这是我写的Qt Mobile应用程序Qt Creator 2.4.0, Based on Qt 4.7.4 (64 bit) Built on Dec 20 2011 at 11:14:33.
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QIODevice>
#include <QStringList>
QFile file("words.txt");
QStringList words;
if( file.open( QIODevice::ReadOnly ) )
{
QTextStream t( &file );
while( !t.eof() ) {
words << t.readline();
}
file.close();
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?提前致谢.
Mat*_*Mat 19
你不能拥有这样的独立代码.所有代码都需要进入函数.
将所有内容包装在一个main函数中,一旦你修复了QTextStream它的使用,你应该没问题(它没有eof方法,也没有readline方法 - 请查看使用示例附带的API文档).
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QIODevice>
#include <QStringList>
int main()
{
QFile file("words.txt");
QStringList words;
if( file.open( QIODevice::ReadOnly ) )
{
QTextStream t( &file );
QString line = t.readLine();
while (!line.isNull()) {
words << line;
line = t.readLine();
}
file.close();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33679 次 |
| 最近记录: |