From 3914906127942051639
X-Google-Thread: f78e5,ac8f7c796c0ee2eb
X-Google-Attributes: gidf78e5,public,usenet
X-Google-Language: ENGLISH,ASCII
Path: g2news1.google.com!news3.google.com!out04b.usenetserver.com!news.usenetserver.com!in02.usenetserver.com!news.usenetserver.com!pd7cy1no!shaw.ca!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: James Kanze <james.kanze@gmail.com>
Newsgroups: comp.std.c++
Subject: Re: std::pair istream >> operator
Date: Tue, 20 Nov 2007 17:27:36 CST
Organization: http://groups.google.com
Lines: 44
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <70cc8b71-e1b1-4a8c-8576-13f8d2265dc8@d50g2000hsf.googlegroups.com>
References: <a7eb92bf-1ab8-438d-8bca-b6f7cfcc056c@o6g2000hsd.googlegroups.com> 
	<Y4l0j.39$xq7.20@newsfe05.lga>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1195598058 30653 127.0.0.1 (20 Nov 2007 22:34:18 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 20 Nov 2007 22:34:18 +0000 (UTC)
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
X-SMTP-Auth: no
Complaints-To: groups-abuse@google.com
Injection-Info: d50g2000hsf.googlegroups.com; posting-host=86.70.189.110; 
	posting-account=1W_PtwoAAAA1QoMcl2Z5P6j-DNc8HR3W
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.6) 
	Gecko/20070725 Firefox/2.0.0.6,gzip(gfe),gzip(gfe)
Content-Disposition: inline
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
X-MIME-Autoconverted: from quoted-printable to 8bit by mulga.csse.unimelb.edu.au id lAKMYPQI023692
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Xref: g2news1.google.com comp.std.c++:9660

On Nov 19, 8:08 pm, tazmas...@rocketmail.com ("Jim Langston") wrote:
> "Andrey" <andrey_rya...@bk.ru> wrote in message

> news:a7eb92bf-1ab8-438d-8bca-b6f7cfcc056c@o6g2000hsd.googlegroups.com...

> > I'm wondering why there is no standard operator defined like
> > the following?

> > template<typename First, typename Second>
> > istream & operator >> (istream & in, pair<First, Second> & p) {
> > return in>>p.first>>p.second;
> > }

> > I always define it by hand.

> Consider, also, that your implemnation can be broken for
> std::pair<std::string, int> since the std::string can contain a space.  In
> which case it might need to be
> std::getline( in, p.first );
> return in >> p.second;

> or even with <int, std::string> you probably want a
> std::getline for the second parameter.

That's a problem with std::string in general.  I use a special
class, ParsableString, when I have to do round trip IO on a
string, and no other solution is readily available.

The problem is that you need a separator, even with
std::pair<int,int>.  And that separator will probably depend on
what the std::pair is being used for.

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient�e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



