C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- è¾å ¥/è¾åºæçºµç¬¦
- std::ios_base
- std::ios_base::failure
- std::ios_base::event_callback
- std::ios_base::seekdir
- std::ios_base::event
- std::ios_base::fmtflags
- std::ios_base::iostate
- std::ios_base::iword
- std::ios_base::pword
- std::ios_base::register_callback
- std::ios_base::sync_with_stdio
- std::ios_base::Init
- std::ios_base::openmode
- std::ios_base::precision
- std::ios_base::width
- std::ios_base::imbue
- std::ios_base::getloc
- std::ios_base::xalloc
- std::ios_base::ios_base
- std::ios_base::~ios_base
- std::ios_base::flags
- std::ios_base::setf
- std::ios_base::unsetf
- C 飿 ¼æä»¶è¾å ¥/è¾åº
- std::basic_streambuf
- std::basic_filebuf
- std::basic_stringbuf
- std::strstreambuf
- std::basic_syncbuf
- std::basic_ios
- std::basic_istream
- std::basic_osyncstream
- std::basic_ostream
- std::basic_iostream
- std::basic_ifstream
- std::basic_ofstream
- std::basic_fstream
- std::basic_istringstream
- std::basic_ostringstream
- std::basic_stringstream
- std::istrstream
- std::ostrstream
- std::strstream
- std::streamoff
- std::streamsize
- std::fpos
- std::iostream_category
- std::io_errc
- std::cin, std::wcin
- std::cout, std::wcout
- std::cerr, std::wcerr
- std::clog, std::wclog
- 注é
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >è¾å ¥/è¾åºåº >std::ios_base > std::ios_base::fmtflags
std::ios_base::fmtflags
| typedef /*implementation defined*/ fmtflags; |
||
| static constexpr fmtflags dec = /*implementation defined*/ static constexpr fmtflags oct = /*implementation defined*/ |
||
| static constexpr fmtflags left = /*implementation defined*/ static constexpr fmtflags right = /*implementation defined*/ |
||
| static constexpr fmtflags scientific = /*implementation defined*/ static constexpr fmtflags fixed = /*implementation defined*/ |
||
| static constexpr fmtflags boolalpha = /*implementation defined*/ static constexpr fmtflags showbase = /*implementation defined*/ |
||
æå®å¯ç¨çæ ¼å¼åæ å¿ã宿¯ä½æ©ç ç±»å (BitmaskType) ãå®ä¹ä¸å常éï¼
| Â | |
| 常é | è§£é |
| dec | ä¸ºæ´æ° I/O 使ç¨åè¿å¶åºï¼è§ std::dec |
| oct | ä¸ºæ´æ° I/O 使ç¨å «è¿å¶åºï¼è§ std::oct |
| hex | ä¸ºæ´æ° I/O 使ç¨åå è¿å¶åºï¼è§ std::hex |
| basefield | dec|oct|hex ãéç¨äºæ©ç è¿ç® |
| left | å·¦æ ¡æ£ï¼æ·»å å¡«å å符å°å³ï¼ï¼è§ std::left |
| right | 峿 ¡æ£ï¼æ·»å å¡«å å符å°å·¦ï¼ï¼è§ std::right |
| internal | å 鍿 ¡æ£ï¼æ·»å å¡«å å符å°å é¨éå®ç¹ï¼ï¼è§ std::internal |
| adjustfield | left|right|internal ãéç¨äºæ©ç è¿ç® |
| scientific | ç¨ç§å¦è®°æ°æ³çææµ®ç¹ç±»åï¼æè¥ä¸ fixed ç»ååç¨åå è¿å¶è®°æ³ï¼è§ std::scientific |
| fixed | ç¨å®ç¹è®°æ³çææµ®ç¹ç±»åï¼æè¥ä¸ scientific ç»ååç¨åå è¿å¶è®°æ³ï¼è§ std::fixed |
| floatfield | scientific|fixed ãéç¨äºæ©ç è¿ç® |
| boolalpha | 以忝æ°åæ ¼å¼æå ¥å¹¶éåº bool ç±»åï¼è§ std::boolalpha |
| showbase | çæä¸ºæ´æ°è¾åºæç¤ºæ°ååºåºçåç¼ï¼è´§å¸ I/O ä¸è¦æ±ç°éæç¤ºå¨ï¼è§ std::showbase |
| showpoint | æ æ¡ä»¶ä¸ºæµ®ç¹æ°è¾åºçæå°æ°ç¹å符ï¼è§ std::showpoint |
| showpos | 为éè´æ°å¼è¾åºçæ + å符ï¼è§ std::showpos |
| skipws | å¨å ·ä½è¾å ¥æä½åè·³è¿å导空ç½ç¬¦ï¼è§ std::skipws |
| unitbuf | 卿¯æ¬¡è¾åºæä½åå²å ¥è¾åºï¼è§ std::unitbuf |
| uppercase | å¨å ·ä½è¾åºçè¾åºæä½ä¸ä»¥å¤§åçä»·æ¿æ¢å°åå符ï¼è§ std::uppercase |
示ä¾
ä¸å示ä¾å±ç¤ºæå°åä¸ç»æçæ°ç§ä¸åæ¹å¼ã
#include <iostream>  int main() { int num = 150;  // 以 fmtflags 为类æå常éï¼ std::cout.setf(std::ios_base::hex, std::ios_base::basefield); std::cout.setf(std::ios_base::showbase); std::cout << num << '\n';  // 以 fmtflags 为继æ¿çç±»æå常éï¼ std::cout.setf (std::ios::hex , std::ios::basefield); std::cout.setf (std::ios::showbase); std::cout << num << '\n';  // 以 fmtflags 为对象æå常éï¼ std::cout.setf(std::cout.hex, std::cout.basefield); std::cout.setf(std::cout.showbase); std::cout << num << '\n';  // 以 fmtflags 为类åï¼ std::ios_base::fmtflags ff; ff = std::cout.flags(); ff &= ~std::cout.basefield; // è§£é¤è®¾ç½® basefield ä½ ff |= std::cout.hex; // 设置 hex ff |= std::cout.showbase; // 设置 showbase std::cout.flags(ff); std::cout << num << '\n';  // ä¸ä½¿ç¨ fmtflags ï¼ä½ä½¿ç¨æçºµç¬¦ï¼ std::cout << std::hex << std::showbase << num << '\n'; }
è¾åºï¼
0x96 0x96 0x96 0x96 0x96
åé
| ç®¡çæ ¼å¼æ å¿ (å ¬å¼æå彿°) | |
| 设置ç¹å®æ ¼å¼æ å¿ (å ¬å¼æå彿°) | |
| æ¸
é¤ç¹å®æ ¼å¼çæ å¿ (å ¬å¼æå彿°) | |
| æ´æ¹ç¨äºæ´æ° I/O çåºæ° (彿°) | |
| æ´æ¹å¡«å
å符 (彿°æ¨¡æ¿) | |
| (C++11)(C++11) |
æ´æ¹ç¨äºæµ®ç¹ I/O çæ ¼å¼å (彿°) |
| æ§å¶æ¯å¦ä½¿ç¨åç¼æç¤ºæ°å¼åºæ° (彿°) | |
| å¨å¸å°å¼çææ¬åæ°å¼è¡¨ç¤ºé´åæ¢ (彿°) | |
æ§å¶æ¯å¦å° + å·ä¸éè´æ°ä¸åä½¿ç¨ (彿°) | |
| æ§å¶æµ®ç¹è¡¨ç¤ºæ¯å¦å§ç»å
å«å°æ°ç¹ (彿°) | |
| æ§å¶æ¯å¦æ¯æ¬¡æä½å岿´è¾åº (彿°) | |
| æ§å¶æ¯å¦è·³è¿è¾å
¥ä¸çå导空ç½ç¬¦ (彿°) | |
| æ§å¶ä¸äºè¾åºæä½æ¯å¦ä½¿ç¨å¤§å忝 (彿°) |