0

Once I try to compile and run program, visual shows this error.

Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)

Overload function:

istream& operator>> (istream& InputStream, Description& rhs) {
InputStream >> rhs.mNumber >> "," >> rhs.mLenght >> "," >> rhs.mName;

return InputStream;
}

Class Description defintion:

class Description {
private:
    int mNumber;
    int mLenght;
    string mName;
public:
    Description();
    Description(int, int, string);
    Description& operator= (const Description&);
    friend ostream& operator<< (ostream&, Description&);
    friend istream& operator>> (istream&, Description&);
};

And yes I did:

#include <iostream>
#include <string>
#include <fstream>
#include <istream>
eniodordan
  • 11
  • 1
  • 4
  • 4
    The code as written attempts to read from `InputStream` and assign something to `","` which is `const` and can't be assigned to. – François Andrieux Nov 07 '18 at 20:10
  • "And yes I did" but what you did not is to provide [mcve] – Slava Nov 07 '18 at 20:12
  • "And yes I did" -- okay, but I didn't. If you want people to help you, provide code that shows the problem. I won't cut and paste to create something that might or might not be what you tried. You know what you did; post it. – Pete Becker Nov 07 '18 at 20:14
  • 1
    https://stackoverflow.com/questions/11374617/the-easiest-way-to-read-formatted-input-in-c – rustyx Nov 07 '18 at 20:14
  • What do you want `InputStream >> ","` to do? If that worked, it would assign a new value to the constant `","`. – Silvio Mayolo Nov 07 '18 at 20:15

1 Answers1

1

In the line

InputStream >> rhs.mNumber >> "," >> rhs.mLenght >> "," >> rhs.mName;

the "," parts are wrong. You can't read anything into a string literal.

If you expect to see the token , in the input stream, you may use:

char dummy;
InputStream >> rhs.mNumber >> dummy >> rhs.mLenght >> dummy >> rhs.mName;
R Sahu
  • 204,454
  • 14
  • 159
  • 270