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::fixed, std::scientific, std::hexfloat, std::defaultfloat
std::fixed, std::scientific, std::hexfloat, std::defaultfloat
| å®ä¹äºå¤´æä»¶ <ios>
|
||
| std::ios_base& fixed( std::ios_base& str ); |
(1) | |
| std::ios_base& scientific( std::ios_base& str ); |
(2) | |
| std::ios_base& hexfloat( std::ios_base& str ); |
(3) | (C++11 èµ·) |
| std::ios_base& defaultfloat( std::ios_base& str ); |
(4) | (C++11 èµ·) |
ä¿®æ¹æµ®ç¹è¾å ¥/è¾åºçé»è®¤æ ¼å¼åã
1) å¦å以è°ç¨ str.setf(std::ios_base::fixed, std::ios_base::floatfield) ï¼è®¾ç½®æµ
str ç floatfield 为 fixed2) å¦å以è°ç¨ str.setf(std::ios_base::scientific, std::ios_base::floatfield) ï¼è®¾ç½®æµ
str ç floatfield 为 scientific3) å¦å以è°ç¨ str.setf(std::ios_base::fixed | std::ios_base::scientific, std::ios_base::floatfield) ï¼è®¾ç½®æµ
str ç floatfield åæ¶ä¸º fixed å scientific ãè¿å¯ç¨åå
è¿å¶æµ®ç¹æ ¼å¼åã4) å¦å以è°ç¨ str.unsetf(std::ios_base::floatfield) ï¼è®¾ç½®æµ
str ç floatfield 为é¶ï¼è¿å¼äº fixed å scientific ãè¿æ¯ä¸ä¸ª I/O æçºµç¬¦ï¼å¯ç¨å¦ out << std::fixed ç表达å¼å¯¹ä»»ä½ std::basic_ostream ç±»åç out æç¨å¦ in >> std::scientific ç表达å¼å¯¹ä»»ä½ std::basic_istream ç±»åç in è°ç¨ã
åæ°
| str | - | å° I/O æµçå¼ç¨ |
è¿åå¼
str ï¼å°æçºµåçæµçå¼ç¨ï¼
注æ
åå è¿å¶æµ®ç¹æ ¼å¼åå¿½ç¥æµç²¾åº¦è§å®ï¼å¦ std::num_put::do_put çè§å®æè¦æ±ã
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <sstream> Â int main() { std::cout << "The number 0.01 in fixed: " << std::fixed << 0.01 << '\n' << "The number 0.01 in scientific: " << std::scientific << 0.01 << '\n' << "The number 0.01 in hexfloat: " << std::hexfloat << 0.01 << '\n' << "The number 0.01 in default: " << std::defaultfloat << 0.01 << '\n'; double f; std::istringstream("0x1P-1022") >> std::hexfloat >> f; std::cout << "Parsing 0x1P-1022 as hex gives " << f << '\n'; }
è¾åºï¼
The number 0.01 in fixed: 0.010000 The number 0.01 in scientific: 1.000000e-02 The number 0.01 in hexfloat: 0x1.47ae147ae147bp-7 The number 0.01 in default: 0.01 Parsing 0x1P-1022 as hex gives 2.22507e-308
åé
| æ´æ¹æµ®ç¹ç²¾åº¦ (彿°) |