Answer the question
In order to leave comments, you need to log in
How to get system locale from std::setlocale?
Good afternoon, how can I get the current locale of the system?
I would like to get something like Russian_Russia.UTF-8, but I get only classic "C" locale
setlocale(LC_ALL, "");
auto l = setlocale(LC_ALL, ""); // тут "C"
Answer the question
In order to leave comments, you need to log in
1) if you use c++, then use std::locale better
2) read the man carefully - it says that if the locale argument (it is the second one) is NULL, then the current locale is returned
3) by default, it is quite possible that the xish locale will be set, therefore, first install what you need, and then get
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main() {
printf("%s\n", setlocale(LC_ALL, NULL));
printf("%s\n", setlocale(LC_ALL, "ru_RU.UTF-8"));
printf("%s\n", setlocale(LC_ALL, NULL));
return 0;
}
➜ /tmp gcc test.c
➜ /tmp ./a.out
C
ru_RU.UTF-8
ru_RU.UTF-8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question