0

I am trying to use a custom template for IO, and I getting an error :

"error C2678: binary '>>' : no operator found which takes a left-hand operand of 
type 'std::ifstream' (or there is no acceptable conversion)"

I have searched and found only suggestions to try including more headers, and have tried including: string, fstream, iostream, istream, vector.
I can use an fstream.get(), but I am trying to get space delimited strings. (The format of my file is lines like this: "String1 = String2")

Here is my code:

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

    return out;
}

Any suggestions are very much appreciated! Thanks!

(P.S. Not sure if it will matter for compiler considerations, but I am using Visual Studio 2013.)

Dharmesh Porwal
  • 1,406
  • 2
  • 12
  • 21
Lapys
  • 87
  • 2
  • 14

2 Answers2

2

The problem is your OutType (which you have not shown us) has no operator>>(istream&, OutType&). You need to define one for every possible OutType.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
0

How you are expecting OutType is known to >> operator? It understands primitives like int,char, etc., but if you want to make OutType available to << you should overload the operator.

Pranit Kothari
  • 9,721
  • 10
  • 61
  • 137