locale


1. Getting the Current Locale:

#include <iostream>
#include <locale>

int main() {
  std::cout << std::locale().name() << '\n';
}

2. Changing the Locale:

#include <iostream>
#include <locale>

int main() {
  std::locale my_locale("en_US.UTF-8");
  std::cout.imbue(my_locale);
  std::cout << "Hello, world!" << '\n';
}

3. Formatting Dates and Times:

#include <iostream>
#include <locale>
#include <ctime>

int main() {
  std::time_t t = std::time(nullptr);
  std::cout.imbue(std::locale("en_US.UTF-8"));
  std::cout << std::ctime(&t);
}

4. Formatting Numbers:

5. Formatting Currency:

6. Sorting Strings According to Locale:

7. Comparing Strings Case-Insensitively:

8. Translating Text:

9. Writing Locale-Aware Applications:

10. Creating and Using Custom Locales:

11. Using the Decimal Separator:

12. Using the Time Zone Name:

13. Formatting Strings for Output:

14. Checking if a Character is a Digit:

15. Converting Strings to Uppercase/Lowercase:

16. Collating Strings: