std::setlocale
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Заголовочный файл <clocale>
|
||
| char* setlocale( int category, const char* locale); |
||
setlocale функция устанавливает указанной локали системы или ее часть, как новый язык C. Изменения остаются в силе и влияет на выполнение всех зависящих от языка C библиотечных функций до следующего вызова setlocale. Если locale является нулевым указателем, setlocale запрашивает текущий стандарт C без изменения его.Original:
The
setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale. If locale is a null pointer, setlocale queries the current C locale without modifying it.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Содержание |
[править] Параметры
[править] Возвращаемое значение
Указатель на узкой нулем строку определения языка C после применения изменений, если таковые имеются, или нулевой указатель в случае неудачи.
Original:
Pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Notes
Во время запуска программы, эквивалент std::setlocale(LC_ALL, "C"); выполняется перед любым пользователем код запускается.
Original:
During program startup, the equivalent of std::setlocale(LC_ALL, "C"); is executed before any user code is run.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Хотя возвращение типа char*, изменения, то к символов неопределенное поведение.
Original:
Although the return type is char*, modifying the pointed-to characters is undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Потому что
setlocale изменяет глобальное состояние которых влияет на выполнение локали-зависимых функций, это неопределенное поведение, чтобы вызвать его из одной нити, а другой поток выполняет любую из следующих функций: std::fprintf, std::isprint, std::iswdigit, std::localeconv, std::tolower, std::fscanf, std::ispunct, std::iswgraph, std::mblen, std::toupper, std::isalnum, std::isspace, std::iswlower, std::mbstowcs, std::towlower, std::isalpha, std::isupper, std::iswprint, std::mbtowc, std::towupper, std::isblank, std::iswalnum, std::iswpunct, std::setlocale, std::wcscoll, std::iscntrl, std::iswalpha, std::iswspace, std::strcoll, std::wcstod, std::isdigit, std::iswblank, std::iswupper, std::strerror, std::wcstombs, std::isgraph, std::iswcntrl, std::iswxdigit, std::strtod, std::wcsxfrm, std::islower, std::iswctype, std::isxdigit.Original:
Because
setlocale modifies global state which affects execution of locale-dependent functions, it is undefined behavior to call it from one thread, while another thread is executing any of the following functions: std::fprintf, std::isprint, std::iswdigit, std::localeconv, std::tolower, std::fscanf, std::ispunct, std::iswgraph, std::mblen, std::toupper, std::isalnum, std::isspace, std::iswlower, std::mbstowcs, std::towlower, std::isalpha, std::isupper, std::iswprint, std::mbtowc, std::towupper, std::isblank, std::iswalnum, std::iswpunct, std::setlocale, std::wcscoll, std::iscntrl, std::iswalpha, std::iswspace, std::strcoll, std::wcstod, std::isdigit, std::iswblank, std::iswupper, std::strerror, std::wcstombs, std::isgraph, std::iswcntrl, std::iswxdigit, std::strtod, std::wcsxfrm, std::islower, std::iswctype, std::isxdigit.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Пример
#include <cstdio> #include <clocale> #include <ctime> #include <cwchar> int main() { // the C locale will be UTF-8 enabled English; // decimal dot will be German // date and time formatting will be Japanese std::setlocale(LC_ALL, "en_US.UTF-8"); std::setlocale(LC_NUMERIC, "de_DE"); std::setlocale(LC_TIME, "ja_JP"); wchar_t str[100]; std::time_t t = std::time(NULL); std::wcsftime(str, 100, L"%A %c", std::localtime(&t)); std::wprintf(L"Number: %.2f\nDate: %Ls\n", 3.14, str); }
Вывод:
Number: 3,14 Date: 月曜日 2011年12月19日 18時04分40秒
[править] См. также
| локали категории std::setlocale Original: locale categories for std::setlocale The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (константа-макрос) | |
| Набор полиморфных аспекты, которые инкапсулируют культурные различия Original: set of polymorphic facets that encapsulate cultural differences The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (класс) | |
| C документация для setlocale
| |