In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the output format control skills of C++", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the output format control skills of C++?"
In C++, the flow of data from one object to another is abstracted as "stream". The input / output stream is formed according to the direction of the flow. C++ provides two different control methods for the input and output format of stream data, one is to set the input and output format by using setf, width and other functions provided by the ios_base class, and the other is through the overloaded format control character "" and the stream format control object.
The input and output formats of most streams can be set using the setf function. This function has two overloaded forms. The setf prototypes of its parameters are:
Fmtflage setf (fmtfalg flag)
Parameter flag describes the format to be set, which is given by ios_base. It is advisable to enumerate constants as follows:
Enum {left = 0x0001, / / output right = 0x0002 on the left in the field, / / output internal = 0x0004 on the right in the field, / / sign on the left, output dec = 0x0008 by default, / / output hex = 0x0010 in decimal, / / output oct = 0x0020 in hexadecimal, fixed = 0x0040 in hexadecimal, / / float output scientific = 0x0080 in decimal form / / floating-point numbers output boolalpha = 0x0100 in scientific counting mode, / / Boolean values output showbase = 0x0200 in true/false mode, / / 8 is preceded by 0 as indicator, hexadecimal is preceded by 0x as indicator showpoint = 0x0400, / / regardless of whether 0 of decimal point and trailing part can be omitted or not, output decimal point and 0 showpos = 0x0800, / / output + sign skipws = 0x1000 before positive number, / / do not read blank character (space) Tabs\ t, carriage returns\ r, and line feeds\ n) unitbuf = 0x2000, / / each write data is refreshed to the corresponding device uppercase = 0x4000, / / Scientific counter "e" and hexadecimal count "x", capitalized output is "E" and "X" adjustfield = left | right | internal, / / shielding code generally used for alignment basefield = dec | hex | oct / / Shield code floatfield = scientific commonly used as numeric binary output mode | fixed / / shielding code commonly used as floating point output mode}
Generally use the derived class ios as the prefix "ios::" to use the above enumerated values.
Another usage prototype of the Setf function is as follows:
Fmtflags setf (fmtflags flag,fmtflags mask)
The second function mask is in hidden code format. For example, set adjustfield,basefield and floatfield format. All formats that make up the hidden code format are first reset, and then the new format is set with * parameter flag.
The format set by the setf function can be reset with the unsetf function. Here is his prototype, with the parameter mask to the format you want to reset.
Void unsetf (fmtflags mask)
The following program uses the setf/unsetf function to format and reset the built-in cout stream.
# include using namespace std; int main (void) {/ / Scientific count display, uppercase E cout.setf (ios::scientific | ios::uppercase); cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.