我收到所有设置函数的错误 错误:'。'之前的预期primary-expression令牌: All.push_back(Country.setName(国家[0])); ^
这是repository.cpp
#include "repository.h"
#include <QFile>
#include <QTextStream>
void Repository::PopulateList()
{
QFile file(":/countries.txt");
if(file.open(QIODevice::ReadOnly))
{
QTextStream str(&file);
while (!str.atEnd())
{
QString line = str.readLine();
QStringList country = line.split(" ");
All.push_back(Country.setName(country[0]));
All.push_back(Country.setArtist(country[1]));
All.push_back(Country.setSong(country[2]));
All.push_back(Country.setScore(0));
}
}
file.close();
}
这是repository.h
#ifndef REPOSITORY_H
#define REPOSITORY_H
#include <country.h>
#include <QString>
#include <vector>
class Repository
{
private:
std::vector<Country> All;
void PopulateList();
public:
Repository();
std::vector<Country> getAll(){return this->All;}
};
#endif // REPOSITORY_H
我在做什么?
答案 0 :(得分:3)
如果要将“国家/地区”对象添加到列表中,则需要声明一个,将其设置为值,然后将其添加到列表中:
std::setw