A program cannot necessarily imbue a new locale on a stream or stream buffer at any particular time. Problems are likely if a new locale is imbued on a stream buffer with a state-dependent code conversion, since the buffer might very well be in the middle of a state-dependent conversion. In such a situation, the code conversion facet contained in the new locale would likely be at loose ends indeed. To avoid problems, follow these guidelines for imbuing locales:
A new locale can always be imbued immediately after construction of a stream or stream buffer, in other words, before any other operation is attempted.
A new locale can always be imbued after an operation that flushes the stream buffer.