Put the whole value into char

I need to put the whole integral value into char from ifstream.
(In this concrete meaning char is 1 byte int)
But if I put it just into char, it extracts only 1 symbol, not the whole number like for int.
So I have to do
char VALUE;
int temp;
is >> temp;
VALUE = temp;

Not cool.
Can I put the value into char directly, extracting the whole value + whitespaces? (with ifstream)
You could override operator >>:
1
2
3
4
5
6
7
std::ifstream& operator >> (std::ifstream& in, char& value)
{
	int int_value = 0;
	in >> int_value;
	value = int_value;
	return in;
}

But then, this override is used everywhere in your program (actually, in current translaction unit).
Otherwise, you could create a function and use wherever you want:
1
2
3
4
5
6
char read_char(std::ifstream& in)
{
	int int_value = 0;
	in >> int_value;
	return int_value;
}

char VALUE = read_char(is);
Topic archived. No new replies allowed.