0

Reading a lot about encoding finally I got confused!
I summarize my confusion into two questions:

  1. is there any encoding at stream level? I mean, is setting the encoding of an stream has any meaning? or streams are totally unaware of encoding?

  2. If streams are unaware of encoding, then what's the main purpose of std::locale and std::imbue?

MBZ
  • 26,084
  • 47
  • 114
  • 191
  • For working with wide characters, see the bottom half of http://www.cplusplus.com/reference/iostream/ – kfsone Jun 24 '13 at 06:56

1 Answers1

1
  1. No, not really. Although all file I/O operations performed through std::basic_filebuf<CharT> use the std::codecvt<CharT, char, std::mbstate_t> facet of the locale imbued in the stream.

  2. The main purpose of std::basic_ios::imbue is to make the stream to format stuff in a locale dependent manner. For instance the decimal separator, thousand separator, and such.

dalle
  • 18,057
  • 5
  • 57
  • 81
  • what's the default `std::codecvt` then? – MBZ Jun 24 '13 at 14:34
  • @MBZ: The `std::codecvt` does nothing, the `std::codecvt` does locale- and compiler-specific conversion between wide string and narrow string. See your compiler documentation for information about the `wchar_t` one. – dalle Jun 24 '13 at 17:18