Nov 6, 2011 at 4:26pm UTC
I'm using istream to get 'general' input from the user (maybe from a file, from keyboard, etc.) using a template.
template<typename T>
void ClassName<T>::SomeFunction { //forgot to put this line in, might've caused confusion
istream input;
T thing;
while (input >> thing)
{
// do stuff in here
// an array of type T will contain thing
}
}
I only want to record int and double types (which T can handle) but if it sees any other type (like a string or a char) then it will stop.
So far it crashes when I enter a letter. Is there a way to "stop" or "exit" the input stream when it sees a string or letter?
Last edited on Nov 6, 2011 at 4:42pm UTC
Nov 6, 2011 at 4:37pm UTC
Your code doesn't make total sense. Are you wanting to read either a sequence of ints or a sequence of doubles?
Nov 6, 2011 at 4:41pm UTC
I want to read in either a bunch of int or a bunch of double, which is why I'm using a template. The problem is that I don't know how to stop the input stream if a suddenly different type comes in or end of file.