C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- std::locale
- std::use_facet
- std::has_facet
- std::isspace(std::locale)
- std::isblank(std::locale)
- std::codecvt
- std::wstring_convert
- std::iscntrl(std::locale)
- std::isupper(std::locale)
- std::islower(std::locale)
- std::isalpha(std::locale)
- std::isdigit(std::locale)
- std::ispunct(std::locale)
- std::isxdigit(std::locale)
- std::isalnum(std::locale)
- std::isprint(std::locale)
- std::isgraph(std::locale)
- std::toupper(std::locale)
- std::tolower(std::locale)
- std::wbuffer_convert
- std::ctype_base
- std::codecvt_base
- std::messages_base
- std::time_base
- std::money_base
- std::ctype
- std::ctype<char>
- std::collate
- std::messages
- std::time_get
- std::time_put
- std::num_get
- std::num_put
- std::numpunct
- std::money_get
- std::money_put
- std::moneypunct
- std::ctype_byname
- std::codecvt_byname
- std::messages_byname
- std::collate_byname
- std::time_get_byname
- std::time_put_byname
- std::numpunct_byname
- std::moneypunct_byname
- std::codecvt_utf8
- std::codecvt_utf16
- std::codecvt_utf8_utf16
- std::codecvt_mode
- std::setlocale
- std::localeconv
- std::lconv
- LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME
- 注é
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >æ¬å°ååº > std::num_put
std::num_put
| å®ä¹äºå¤´æä»¶ <locale>
|
||
| template< Â Â class CharT, |
||
ç±» std::num_put å°è£
æ ¼å¼åæ°å¼ä¸ºå符串çè§åãå
·ä½èè¨æ¯æ bool ã long ã unsigned long ã long long ã unsigned long long ã double ã long double ã void* ç±»ååææè½éå¼è½¬æ¢å°å®ä»¬çç±»åï¼ä¾å¦ int æ float ï¼ãæ åæ ¼å¼åè¾åºè¿ç®ç¬¦ï¼å¦ cout << n; ï¼ç¨ I/O æµç locale ç std::num_put å¹³é¢çææ°åçææ¬è¡¨ç¤ºã
ç»§æ¿å¾
ç±»åè¦æ±
-OutputIt å¿
须满足éçè¾åºè¿ä»£å¨ (LegacyOutputIterator) çè¦æ±ã
|
ç¹å
æ ååºæä¾äºä¸ªå¤ç«ï¼ç¬ç«äºæ¬å°ç¯å¢ï¼çå ¨ç¹ååäºä¸ªé¨åç¹åï¼
| å®ä¹äºå¤´æä»¶
<locale> | |
| std::num_put<char> | å建æ°ççªå符串表示 |
| std::num_put<wchar_t> | å建æ°ç宽å符串表示 |
| std::num_put<char, OutputIt> | ç¨å®å¶è¾åºè¿ä»£å¨å建æ°ççªå符串表示 |
| std::num_put<wchar_t, OutputIt> | ç¨å®å¶è¾åºè¿ä»£å¨å建æ°ç宽å符串表示 |
å¦å¤ï¼ C++ ç¨åºä¸æé çæ¯ä¸ª locale 对象é½å®è£ è¿äºç¹åçå ¶èªèº«ï¼æ¬å°ç¯å¢éå®ï¼çæ¬ã
æåç±»å
| Â | |
| æåç±»å | å®ä¹ |
char_type
|
CharT
|
iter_type
|
OutputIt
|
æå彿°
| æé æ°ç num_put å¹³é¢ (å ¬å¼æå彿°) | |
| 鿝 num_put å¹³é¢ (åä¿æ¤æå彿°) | |
è°ç¨ do_put (å ¬å¼æå彿°) |
åä¿æ¤æå彿°
| [è] |
æ ¼å¼åæ°åå¹¶åå
¥å°è¾åºæµ (èåä¿æ¤æå彿°) |
æå对象
| static std::locale::id id |
locale ç id (å ¬å¼æå对象) |
示ä¾
#include <iostream> #include <locale> #include <string> #include <iterator>  int main() { double n = 1234567.89; std::cout.imbue(std::locale("de_DE")); std::cout << "Direct conversion to string:\n" << std::to_string(n) << '\n' << "Output using a german locale:\n" << std::fixed << n << '\n' << "Output using an american locale:\n"; // ç´æ¥ä½¿ç¨å¹³é¢ std::cout.imbue(std::locale("en_US.UTF-8")); auto& f = std::use_facet<std::num_put<char>>(std::cout.getloc()); f.put(std::ostreambuf_iterator<char>(std::cout), std::cout, ' ', n); std::cout << '\n'; }
è¾åºï¼
Direct conversion to string: 1234567.890000 Output using a german locale: 1.234.567,890000 Output using an american locale: 1,234,567.890000
åé
| å®ä¹æ°å¼æ ç¹è§å (类模æ¿) | |
| ä»è¾å
¥å符åºåä¸è§£ææ°åå¼ (类模æ¿) | |
| (C++11) |
è½¬æ¢æ´æ°ææµ®ç¹å¼ä¸º string (彿°) |
| (C++11) |
è½¬æ¢æ´æ°ææµ®ç¹å¼ä¸º wstring (彿°) |