1. Character conversion 1.1 Related class lexical_cast bad_lexical_cast 1.2 definition file: #include
Using namespace std;
Main () {int i = 100; char * pstr = "10101"; cout << "Before Convert I is:" << i << endl; i = boost :: lexical_cast
Using namespace std; using boost :: format; using boost :: oi :: group; int main () {format fmt ("% 1%% 2%% 3%% 4%% 5% 6% / N") // Use% 1% to replace, 1 represents the first parameter string Str; int i = 100; cout << fmt% 'g'% 'A'% 'L'% 'P'% 'H'% 'y' << endl; //% operator pressure into parameter string s_tmp = boost :: STR (FMT); // STR () free function, fomat-> string // can also use format.str (); Cout << S_TMP; RETURN 0;} 2.5 Format Description: "$" Using: Rear PRINTF's Format Control "|" Add: Simplified Printf's Format Control 1. No parameter order: Format ("% 5D% 4S% 5F "); //% rear directly adds the printf format control, the parameter order is introduced into format ("% | 5 |% | 4 |% | 5 |); // Effects the same, automatic judgment D, S, F and other control symbols 2. Parameter sequence: format ("% 1%% 2%% 1%"); format ("% 1 $ 5D% 2 $ 5S% 1 $ 5D); format ("% | 1 $ 5 | % | 2 $ 5 |% | 1 $ 5 |); // Effects the same, automatic judgment D, S, F and other control symbols 3. Specific format: [n $] [flags] [width] [. Precision] Type-char
FlagMeaningeffect on internal stream '-' left alignmentN / A (applied later on the string) '=' centered alignmentN / A (applied later on the string) - note: added feature, not in printf - '_'internal alignmentsets internal alignment - note: added feature, not in printf - ' ' show sign even for positive numberssets showpos '#' show numerical base, and decimal pointsets showbase and showpoint'0'pad with 0's (inserted after sign or base indicator) if not left- . aligned, calls setfill ( '0') and sets internal Extra actions are taken after stream conversion to handle user-defined output '' if the string does not begin with or -, insert a space before the converted stringN / A (applied later on the string) Different to printf's behaviour: it is not affected by internal alignmentType-CharMeaningeffect on streamp or xhexadecimal outputsets hexooctal outputsets octescientific float formatsets floatfield bits to scientificffixed float formatsets floatfield bits to fixedggeneral -default- float formatunset a ll floatfield bitsX, E or Gsame effect as their lowercase counterparts, but using uppercase letters for number outputs. (exponents, hex digits, ..) same effects as 'x', 'e', or 'g', plus uppercased, i or udecimal type outputsets basefield bits to decs or sstring outputprecision specification is unset, and its value goes to an internal field for later 'truncation'. (see precision explanation above) c or C1-character outputonly the first character of the conversion string is used .% print the character% N / A