I'm trying to overload the >> operator to read a single (created with enum Symbol {e,a,b,c,d};
) Symbol:
istream & operator >> (istream & is, Symbol & sym) {
Symbol Arr[]={e,a,b,c,d};
char ch;
is>>ch;
if (strchr("eabcd",ch))
sym=Arr[ch-'e'];
else {
is.unget();
is.setstate(ios::failbit);
}
return is;
}
But this reads some trash (numbers) instead of what I was looking for, leading to a segmentation fault when trying to print it with my << overload, what am I doing wrong?
Edit: Oh, and of course I did add using namespace std;
at the start, same with including iostream
and cstring
.