Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!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 10:00:47 +1200 Lines: 66 Message-ID: <9dn80fFr5dU10@mid.individual.net> References: <9dn78fFr5dU9@mid.individual.net> <513997ec-6237-45a1-8038-7c471c221c87@j1g2000yqn.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net naZHWBpNPvQyczW6+1F2AQSXGzz/KQI82mMI3oiCgcMctlmGab Cancel-Lock: sha1:yVPYWmoZXRv2ytGS+kV/dOib59Q= 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: <513997ec-6237-45a1-8038-7c471c221c87@j1g2000yqn.googlegroups.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:10262 On 09/19/11 09:53 AM, persres@googlemail.com wrote: > On Sep 18, 10:47 pm, Ian Collins wrote: >> On 09/19/11 09:27 AM, pers...@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. Please don't quote signatures > It does compile and works as expected. This is standard way of > copying. I'd better try it then... cat x.cc #include #include #include #include #include using namespace std; int main() { string str("12 3213 asdf 21"); vector v; copy(istream_iterator(istringstream(str)) , istream_iterator(), back_inserter(v) ); } g++ x.cc x.cc: In function ‘int main()’: x.cc:13:48: error: no matching function for call to ‘std::istream_iterator::istream_iterator(std::istringstream)’ CC x.cc "x.cc", line 13: Error: Cannot cast from std::istringstream to std::istream_iterator, int>. -- Ian Collins