Re: changing istream default delimiter
On Mar 31, 5:56 am, "Amadeus W.M." <amadeu...@verizon.net> wrote:
On Mon, 30 Mar 2009 02:39:21 -0700, James Kanze wrote:
It's also a hack, and abuse of the locale. As such, it can
only server to confuse the reader.
Meanwhile I've turned to boost tokenizer to parse a line,
which can handle commas within quotes too, so doing it using
facets is only a matter of curiosity now.
In other words, you're using a tool designed for the job, rather
than a tool designed for a different job.
FWIW, if you do want to change the definition of what istream
thinks is white space, you have to:
1. Create an instance of a ctype<char> facet which defines
white space as you want. Exceptionally (because creating
new facets is normally anything but trivial), this is
simple; the standard provides a specialization of ctype for
char, which has a constructor which takes a table specifying
the types of each char, so all you have to do is write the
table and create an instance of this specialization.
Note that locale reference counts facets, so you should use
new to create the instance, and let locale itself take care
of the delete.
2. Create a locale using this facet. For this, you'd probably
use the templated constructor template< typename Facet >
std::locale::locale( std::locale const& other, Facet* ),
which creates a copy of other, with the given facet
replacing the one in the original locale.
3. Imbue your stream with this locale.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34