Outputting and input with a class

I have this very simple class. I want the input and output to work with the string however for both I get an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
class bin
{
	public:
		int base10;
		std::string binary;
		friend std::ostream& operator<<(std::ostream& os, const bin& dt)
		{
			os << dt.binary;
			return os;
		}
		friend std::istream& operator >> (std::istream& is, const bin& x)
		{
			is >> x.binary;
			return is;
		}
};

For the output operator I get "no operator found which takes a right-hand operand of type 'const std::string'(or there is no acceptable conversion)" And for the input operator I get "no operator found which takes a left-hand operand of type 'std::istream'(or there is no acceptable conversion)"

Note: I removed a lot of the code that wasn't relevant to the problem however if needed I can post the other methods of the class.
Last edited on
closed account (48T7M4Gy)
line 13 remove const and all your problems are gone. (Well until the next one comes along) :)
Just think, how can you write to something 'const'?
Topic archived. No new replies allowed.