Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: stl copy and istream_iterator and operator >> Date: Mon, 19 Sep 2011 09:47:59 +1200 Lines: 29 Message-ID: <9dn78fFr5dU9@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net QqsNXk5csNMdtNmijZO73wz1AhyPWFMjAngxpFaqkQtj6L9+91 Cancel-Lock: sha1:Mnc+UaeNc9wx5Z/62CkCAQ+fXYw= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:10260 On 09/19/11 09:27 AM, persres@googlemail.com wrote: > Hi, > I have the following code - > > string str("12 3213 asdf 21"); > vector v; > > copy(istream_iterator(istringstream(str)) , > istream_iterator(), back_inserter(v) ); This shouldn't compile. You can't create an istream_iterator from a temporary. > I expected copy to throw because the operator>> would have failed due > to the 'asdf' string present. Which operator >>? > However, it doesn't throw. Do you know why, Because the code doesn't do what you think it does (assuming you get it to compile). Have a look at the vector contents. > How can i get it to throw or return an errror. You can provide your own input iterator type. -- Ian Collins