![]() It may make more sense to ignore the fact that they're both stored in a locale, and think only of the individual facets involved: ![]() So, the basic difference between an istream_iterator and an istreambuf_iterator is that the data coming out of an istreambuf_iterator hasn't gone through (most of the) transformations done by the locale, but data coming out of an istream_iterator has been transformed by the locale.įor what it's worth, that "most of the" in the previous paragraph is referring to the fact that when you read data from an istreambuf (via an iterator or otherwise) one little bit of locale-based transformation is done: along with various "formatting" kinds of things, the locale contains a codecvt facet, which is what's used to convert from some external representation to some internal representation (e.g., UTF-8 to UTF-32). This allows code to deal with data in a localized format without being written explicitly for any particular locale. Using an empty string basically tells the runtime library to select the locale it "thinks" is the most suitable, usually based on how the user has configured the operating system. One that's particularly interesting is one that's selected by an empty string. You can choose locales to use by names specified in strings. You can, however, imbue a stream with a different locale of your choice. This is pretty basic-numbers are just converted as a stream of digits, the only things it recognizes as letters are the 26 lower case and 26 upper case English letters, and so on. The standard defines a number of facets for everything from reading and writing numbers ( num_get, num_put) to classifying characters (the ctype facet).īy default, a stream will use the "C" locale. A facet object defines a single facet of an overall locale. It uses those to direct the locale how and where to do a conversion (e.g., convert this number to a string in that buffer with width 8 and precision 5).Īlthough you didn't ask directly about it, the locale in its turn is really just a container-but (for rather an oddity) a typesafe heterogeneous container. The iostream stores some state about how conversions should be done (e.g., the current width and precision for a conversion). ![]() Here's a really badly kept secret: an iostream per se, has almost nothing to do with actually reading or writing from/to a file on your computer.Īn iostream basically acts as a "matchmaker" between a streambuf and a locale: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |