c++ - 为什么这里会报”没有与参数列表匹配的 重载函数 "getline" 实例“ 的错误?
本文介绍了c++ - 为什么这里会报”没有与参数列表匹配的 重载函数 "getline" 实例“ 的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我在把C++primer中的433页代码照着敲到vs2015后,出现以下问题。
#include<vector>
#include<string>
#include<map>
#include<memory>
#include<set>
class QueryResult;
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>>> wm;
};
TextQuery::TextQuery(std::ifstream &is) :file(new std::vector<std::string>)
{
std::string text;
while (getline(is, text)) {//这里getline会标红,出现前面所述的错误
file->push_back(text);
int n = file->size() - 1;
istringstream line(text);//这里line会标红,报错:不允许使用不完整的类型
std::string word;
while (line >> word) {//这里>>会标红:禁止显示状态
没有与这些操作数匹配的 ">>" 运算符
}
}
}
解决方案
#include <fstream> // file stream
#include <sstream> // string stream
这篇关于c++ - 为什么这里会报”没有与参数列表匹配的 重载函数 "getline" 实例“ 的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文