Is it possible to use an istream_iterator<customstruct> to insert into a vector by reading from stdin from a human? The struct has multiple data types contained in it.
Does it make any sense to do so or would prompting for each piece of data separately be the better approach? I only ask this because I was asked to do so, but don’t think it is possible / practical.
Anything can be read by istream_iterator if there is an overload of “operator >>”, and it’s copyable and assignable.
Although it’s possible, I don’t think it’s a good way of reading, since user have to manually type an EOF sequence to make the iterator reach an end.
To avoid the use of EOF, you can let the user input a number of records, but most people is unlikely to know the number of records before they input it.
A better choice might be reading by line and use a stringstream to fetch data. In this way you can recognize some predefined pattern (like empty line) as the end of input before you send them to stringstream as data.