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::setbase
std::setbase
| å®ä¹äºå¤´æä»¶ <iomanip>
|
||
| /*unspecified*/ setbase( int base ); |
||
设置æµçæ°å¼åºãç¨äºè¡¨è¾¾å¼ out << setbase(base) æ in >> setbase(base) æ¶ï¼åå³äº base çå¼ï¼æ´æ¹æµ out æ in ç basefield æ å¿ï¼
- å¼ 16 设置
basefield为 std::ios_base::hex - å¼ 8 设置 std::ios_base::oct
- å¼ 10 设置 std::ios_base::dec ã
å¼äº 8 ã 10 æ 16 ç base å¼éç½® basefield 为é¶ï¼è¿å¯¹åºåè¿å¶è¾åºåä¾èµåç¼çè¾å
¥ã
åæ°
| base | - | basefield çæ°å¼ |
è¿åå¼
è¿åæªæå®ç±»åç对象ï¼ä½¿å¾è¥ str 为 std::basic_ostream<CharT, Traits> æ std::basic_istream<CharT, Traits> ç±»åçæµåç§°ï¼åè¡¨è¾¾å¼ str << setbase(base) æ str >> setbase(base) 表ç°ä¸ºå¦åæ§è¡ä¸å代ç ï¼
str.setf(base == 8 ? std::ios_base::oct : base == 10 ? std::ios_base::dec : base == 16 ? std::ios_base::hex : std::ios_base::fmtflags(0), std::ios_base::basefield);
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <sstream> #include <iomanip> int main() { std::cout << "Parsing string \"10 0x10 010\"\n"; Â int n1, n2, n3; std::istringstream s("10 0x10 010"); s >> std::setbase(16) >> n1 >> n2 >> n3; std::cout << "hexadecimal parse: " << n1 << ' ' << n2 << ' ' << n3 << '\n'; Â s.clear(); s.seekg(0); s >> std::setbase(0) >> n1 >> n2 >> n3; std::cout << "prefix-dependent parse: " << n1 << ' ' << n2 << ' ' << n3 << '\n'; Â std::cout << "hex output: " << std::setbase(16) << std::showbase << n1 << ' ' << n2 << ' ' << n3 << '\n'; }
è¾åºï¼
Parsing string "10 0x10 010" hexadecimal parse: 16 16 16 prefix-dependent parse: 10 16 8 hex output: 0xa 0x10 0x8
åé
| æ´æ¹ç¨äºæ´æ° I/O çåºæ° (彿°) | |
| æ§å¶æ¯å¦ä½¿ç¨åç¼æç¤ºæ°å¼åºæ° (彿°) |