C++ 使用运算符'的编译器错误&燃气轮机&燃气轮机';使用ifstream

C++ 使用运算符'的编译器错误&燃气轮机&燃气轮机';使用ifstream,c++,visual-c++,io,C++,Visual C++,Io,我试图为IO使用自定义模板,但出现了一个错误: "error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion)" 我只搜索并找到了尝试包含更多标题的建议,并尝试包括:string、fstream、iostream、istream、vector我可以使用fstream

我试图为IO使用自定义模板,但出现了一个错误:

"error C2678: binary '>>' : no operator found which takes a left-hand operand of 
type 'std::ifstream' (or there is no acceptable conversion)"
我只搜索并找到了尝试包含更多标题的建议,并尝试包括:
string、fstream、iostream、istream、vector

我可以使用fstream.get(),但我正在尝试获取以空格分隔的字符串。(我的文件格式如下:
“String1=String2”

这是我的密码:

template <typename OutType>
OutType Read(std::ifstream& in)
{
    OutType out;
    in >> out;

    return out;
}
模板
输出类型读取(std::ifstream&in)
{
淘汰;
输入>>输出;
返回;
}
非常感谢您的任何建议!谢谢


(顺便说一句,我不确定这对编译器的考虑是否重要,但我正在使用Visual Studio 2013。)

问题是您的
OutType
(您没有向我们展示)没有
操作符>(istream&,OutType&)
。您需要为每个可能的
OutType
定义一个
操作员知道您期望的
OutType
?它理解诸如
int
char
等基本体,但如果您想使OutType对其可用,以及当您尝试调用它时什么是OutType?可能应该阅读。@MattMcNabb更新了我的答案。