class TextQuery
{
public:
using line_no = std::vector<std::string>::size_type;
TextQuery(std::ifstream&);
QueryResult query(const std::string&) const;
private:
std::shared_ptr<std::vector<std::string>> file;
std::map<std::string, std::shared_ptr<std::set<line_no>>> vm;
};
TextQuery::TextQuery(std::ifstream &is): file(new std::vector<std::string>)
{
std::string text;
while (std::getline(is, text)) {
file->push_back(text);
int n = file->size() - 1;
std::istringstream line(text);
std::string word;
while (line >> word) {
auto& lines = vm[word];
if (!lines) {
lines.reset(new std::set<line_no>);
}
lines->insert(n);
}
}
}
IDE: visual studio 2019 error line:
while (std::getline(is, text)) {
the IDE inferred the argument list types of the getline function is "std::ifstream, std::string". so this is inconsistent with the signature of the getline (string) function. but is
parameter is from function parameter which has type of "std::ifstream &". I am confused here why IDE infer it as "std::ifstream" instead of "std::ifstream &" ? can anybody give some thoughts about how to fix this?
Aucun commentaire:
Enregistrer un commentaire