2013-12-13 81 views
-1

想知道错误是什么..>>操作上ifstream的

C:lab1a.cpp(16):错误C2678:二进制 '>>':没有运营商发现其采用的左手操作输入“的std :: ifstream的”(或没有可接受的转化率)

#include "StdAfx.h" // precompiled 
#include <iostream> 
#include <fstream> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 

#include <vector> 

using namespace std; 

// No checking of end of stream etc. 
void getw(string& t, ifstream& in) 
{ 
    in >> t; 
} 
+0

您已经为您显示的内容添加了大量额外的标题,但没有包含您正在使用的标题。 – chris

+0

在这里编译没有窥视。虽然@chris有一个问题。 ''缺少。 –

+0

>>必须超载! –

回答

0

与此代码的关键错误是,它缺少<string>报头。因为它不支持检查错误(我意识到流的状态仍然可以被检查,但返回流的状态使它更有可能被检查),除此之外,接口本质上被破坏。而且,像这样的函数应该在std::istream而不是std::ifstream的条件下执行,因为它不使用任何具体的std::ifstrean