C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- è¾å ¥/è¾åºæçºµç¬¦
- std::showpoint, std::noshowpoint
- std::setprecision
- std::fixed, std::scientific, std::hexfloat, std::defaultfloat
- std::setbase
- std::showbase, std::noshowbase
- std::quoted
- std::boolalpha, std::noboolalpha
- std::dec, std::hex, std::oct
- std::setfill
- std::setw
- std::left, std::right, std::internal
- std::showpos, std::noshowpos
- std::uppercase, std::nouppercase
- std::ws
- std::ends
- std::skipws, std::noskipws
- std::flush
- std::endl
- std::flush_emit
- std::unitbuf, std::nounitbuf
- std::emit_on_flush, std::no_emit_on_flush
- std::resetiosflags
- std::setiosflags
- std::get_money
- std::get_time
- std::put_money
- std::put_time
- C 飿 ¼æä»¶è¾å ¥/è¾åº
- std::basic_streambuf
- std::basic_filebuf
- std::basic_stringbuf
- std::strstreambuf
- std::basic_syncbuf
- std::basic_ios
- std::basic_istream
- std::ios_base
- 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::dec, std::hex, std::oct
std::dec, std::hex, std::oct
| å®ä¹äºå¤´æä»¶ <ios>
|
||
| std::ios_base& dec( std::ios_base& str ); |
(1) | |
| std::ios_base& hex( std::ios_base& str ); |
(2) | |
| std::ios_base& oct( std::ios_base& str ); |
(3) | |
ä¿®æ¹æ´æ° I/O çé»è®¤æ°å¼åºã
1) å¦å以è°ç¨ str.setf(std::ios_base::dec, std::ios_base::basefield) è®¾ç½®æµ str ç basefield 为 dec
2) å¦å以è°ç¨ str.setf(std::ios_base::hex, std::ios_base::basefield) è®¾ç½®æµ str ç basefield 为 hex
3) å¦å以è°ç¨ str.setf(std::ios_base::oct, std::ios_base::basefield) è®¾ç½®æµ str ç basefield 为 oct
è¿æ¯ä¸ä¸ª I/O æçºµç¬¦ï¼å¯ç¨å¦ out << std::hex ç表达å¼å¯¹ä»»ä½ std::basic_ostream ç±»åç out æç¨å¦ in >> std::hex ç表达å¼å¯¹ä»»ä½ std::basic_istream ç±»åç in è°ç¨ã
åæ°
| str | - | å° I/O æµçå¼ç¨ |
è¿åå¼
str ï¼å°æçºµåçæµçå¼ç¨ï¼
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <sstream> int main() { std::cout << "The number 42 in octal: " << std::oct << 42 << '\n' << "The number 42 in decimal: " << std::dec << 42 << '\n' << "The number 42 in hex: " << std::hex << 42 << '\n'; int n; std::istringstream("2A") >> std::hex >> n; std::cout << std::dec << "Parsing \"2A\" as hex gives " << n << '\n'; // è¾åºåºåºæ¯æä¹ çï¼ç´è³æ´æ¹ std::cout << std::hex << "42 as hex gives " << 42 << " and 21 as hex gives " << 21 << '\n'; }
è¾åºï¼
The number 42 in octal: 52 The number 42 in decimal: 42 The number 42 in hex: 2a Parsing "2A" as hex gives 42 42 as hex gives 2a and 21 as hex gives 15
åé
| æ´æ¹ç¨äºæ´æ° I/O çåºæ° (彿°) | |
| æ§å¶æ¯å¦ä½¿ç¨åç¼æç¤ºæ°å¼åºæ° (彿°) |