基本上我做了一个简单的程序来读取一行文本,但每当我运行程序时,我都会收到错误
no match for 'operator>>' (operand types are 'QFile' and 'QString')
while(file >> name >> month >> day >> year >> subject >> level >> apages >> total >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine >> ten)
和另一个错误:
expected unqualified-id before '<<' token
QDebug << QString(name);
我一直想在网上找一些东西一小时,但我真的找不到任何有效或我能理解的东西。我真的很感激可以提供的任何输入。
相关代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore/QCoreApplication>
#include <QtCore>
#include <QFile>
#
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString name, month, subject, level;
int day, year, apages, total, one, two, three, four, five, six, seven, eight, nine, ten;
QFile file("C:/Users/brandan/Desktop/GUIPrograms/Kumon.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
while(file >> name >> month >> day >> year >> subject >> level >> apages >> total >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine >> ten)
{
QDebug << name << month << day << year << subject << level << apages << total << one << two << three << four << five << six << seven << eight << nine << ten;
}
}