Function template to read both int and string
A question from a c++ newbie.
I'm implementing a function template that reads from an input stream. The type of input is not known and can be int, char, string, etc. I'm stuck at the point where the input is actually read, that is:
in >> temp;
because I can read almost any type by using the >> operator except a string where I have to use getline().
Is there a way around this in one single function template without overloading it specifically for the string type?
I'm implementing a function template that reads from an input stream. The type of input is not known and can be int, char, string, etc. I'm stuck at the point where the input is actually read, that is:
in >> temp;
because I can read almost any type by using the >> operator except a string where I have to use getline().
Is there a way around this in one single function template without overloading it specifically for the string type?
