Using cin with a custom type

This is a discussion on Using cin with a custom type within the C++ Programming forums, part of the General Programming Boards category; Yeah, me yet again. I tried to avoid bugging you guys, but I've hit a problem that's so puzzlingly nonsensical ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    12

    Question Using cin with a custom type

    Yeah, me yet again. I tried to avoid bugging you guys, but I've hit a problem that's so puzzlingly nonsensical that I can't even begin to figure out what's going on.

    Here's the relevant parts of the code:

    Code:
    class ffbyte
    {
    	unsigned char value_;
    public:
    <stuff>
    	friend istream& operator >> (istream& is, const ffbyte& f); // make it naitively input to cin
    };
    
    
    istream& operator >> (istream& is, const ffbyte& f)
    {
    	is >> int(f.value_); // error happens here
    	return is;
    };
    When I compile the code, it tells me that ">>" cannot take an integer as a right-hand value. That's absolute confusing rubbish! Please help.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Remove the const on the function parameter. You are inputting into the ffbyte, so it is changing and the reference should not be const.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    12
    Sometimes I'm amazed at how much I completely miss when I check my code...

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 05:17 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21