public member function
<ios> <iostream>

std::ios_base::imbue

locale imbue (const locale& loc);
Imbue locale
Associates loc to the stream as the new locale object to be used with locale-sensitive operations.

Before that, the function calls all functions registered through member register_callback with imbue_event as first argument.

Standard stream classes do not inherit this member, but inherit basic_ios::imbue instead, which calls this function, but also imbues the locale to the associated stream buffer, if any.

Parameters

loc
locale imbued as the new locale for the stream.

Return value

The locale object associated with the stream before the call.

Example

1
2
3
4
5
6
7
8
9
10
11
// imbue example
#include <iostream>     // std::cout
#include <locale>       // std::locale

int main()
{
  std::locale mylocale("");   // get global locale
  std::cout.imbue(mylocale);  // imbue global locale
  std::cout << 3.14159 << '\n';
  return 0;
}

This code writes a floating point number using the global locale given by the environment. For example, in a system configured with a Spanish locale as default, this could write the number using a comma decimal separator:
3,14159


Data races

Modifies the stream object.
Concurrent access to the same stream object may cause data races.

Exception safety

Basic guarantee: if an exception is thrown, the stream is in a valid state.

See also