c++ – error: expected unqualified-id before if

c++ – error: expected unqualified-id before if

You cant have free-standing code like that. All code needs to go into functions.

Wrap all that in a main function and you should be ok once youve fixed your use of QTextStream (it has no eof method, and it doesnt have a readline method either – please look at the API docs that come with usage examples).

#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();
  }
}

c++ – error: expected unqualified-id before if

Leave a Reply

Your email address will not be published.