1Printf(3)                        OCaml library                       Printf(3)
2
3
4

NAME

6       Printf - Formatted output functions.
7

Module

9       Module   Printf
10

Documentation

12       Module Printf
13        : sig end
14
15
16       Formatted output functions.
17
18
19
20
21
22
23
24       val  fprintf  :  Pervasives.out_channel -> ('a, Pervasives.out_channel,
25       unit) Pervasives.format -> 'a
26
27
28       fprintf outchan format arg1 ... argN formats the arguments arg1 to argN
29       according  to  the  format  string  format  , and outputs the resulting
30       string on the channel outchan .
31
32       The format is a character string which contains two types  of  objects:
33       plain  characters,  which  are simply copied to the output channel, and
34       conversion specifications, each of which causes conversion and printing
35       of arguments.
36
37       Conversion specifications have the following form:
38
39
40       % [flags] [width] [.precision] type
41
42       In  short, a conversion specification consists in the % character, fol‐
43       lowed by optional modifiers and a type which is  made  of  one  or  two
44       characters. The types and their meanings are:
45
46
47       - d , i , n , l , L , or N : convert an integer argument to signed dec‐
48       imal.
49
50       - u : convert an integer argument to unsigned decimal.
51
52       - x : convert an integer argument to unsigned hexadecimal, using lower‐
53       case letters.
54
55       - X : convert an integer argument to unsigned hexadecimal, using upper‐
56       case letters.
57
58       - o : convert an integer argument to unsigned octal.
59
60       - s : insert a string argument.
61
62       - S : insert a string argument in Caml syntax (double quotes, escapes).
63
64       - c : insert a character argument.
65
66       - C : insert a  character  argument  in  Caml  syntax  (single  quotes,
67       escapes).
68
69       -  f  :  convert  a floating-point argument to decimal notation, in the
70       style dddd.ddd .
71
72       - F : convert a floating-point argument to  Caml  syntax  (  dddd.   or
73       dddd.ddd or d.ddd e+-dd ).
74
75       -  e  or  E : convert a floating-point argument to decimal notation, in
76       the style d.ddd e+-dd (mantissa and exponent).
77
78       - g or G : convert a floating-point argument to  decimal  notation,  in
79       style f or e , E (whichever is more compact).
80
81       - B : convert a boolean argument to the string true or false
82
83
84       -  b  :  convert a boolean argument (for backward compatibility; do not
85       use in new programs).
86
87       - ld , li , lu , lx , lX , lo : convert an int32 argument to the format
88       specified by the second letter (decimal, hexadecimal, etc).
89
90       -  nd  ,  ni  , nu , nx , nX , no : convert a nativeint argument to the
91       format specified by the second letter.
92
93       - Ld , Li , Lu , Lx , LX , Lo : convert an int64 argument to the format
94       specified by the second letter.
95
96       -  a  : user-defined printer. Takes two arguments and applies the first
97       one to outchan (the current output channel) and to the second argument.
98       The  first  argument must therefore have type out_channel -> 'b -> unit
99       and the second 'b .  The output produced by the function is inserted in
100       the output of fprintf at the current point.
101
102       -  t  : same as %a , but takes only one argument (with type out_channel
103       -> unit ) and apply it to outchan .
104
105       - { fmt %} : convert a format string argument. The argument  must  have
106       the same type as the internal format string fmt .
107
108       - ( fmt %) : format string substitution. Takes a format string argument
109       and substitutes it to the internal format string fmt to print following
110       arguments. The argument must have the same type as fmt .
111
112       - !  : take no argument and flush the output.
113
114       - % : take no argument and output one % character.
115
116       - , : the no-op delimiter for conversion specifications.
117
118       The optional flags are:
119
120       - - : left-justify the output (default is right justification).
121
122       - 0 : for numerical conversions, pad with zeroes instead of spaces.
123
124       -  +  : for numerical conversions, prefix number with a + sign if posi‐
125       tive.
126
127       -space: for numerical conversions, prefix number with a space if  posi‐
128       tive.
129
130       - # : request an alternate formatting style for numbers.
131
132       The  optional  width  is an integer indicating the minimal width of the
133       result. For instance, %6d prints an integer, prefixing it  with  spaces
134       to fill at least 6 characters.
135
136       The  optional  precision  is a dot .  followed by an integer indicating
137       how many digits follow the decimal point in the %f , %e , and  %E  con‐
138       versions. For instance, %.4f prints a float with 4 fractional digits.
139
140       The  integer  in  a  width or precision can also be specified as * , in
141       which case an extra integer argument is taken  to  specify  the  corre‐
142       sponding  width  or  precision . This integer argument precedes immedi‐
143       ately the argument to print.  For instance, %.*f prints a float with as
144       many  fractional  digits  as the value of the argument given before the
145       float.
146
147
148
149
150       val printf : ('a, Pervasives.out_channel, unit) Pervasives.format -> 'a
151
152       Same as Printf.fprintf , but output on stdout .
153
154
155
156
157       val eprintf : ('a, Pervasives.out_channel, unit)  Pervasives.format  ->
158       'a
159
160       Same as Printf.fprintf , but output on stderr .
161
162
163
164
165       val ifprintf : 'a -> ('b, 'a, unit) Pervasives.format -> 'b
166
167       Same as Printf.fprintf , but does not print anything.  Useful to ignore
168       some material when conditionally printing.
169
170
171
172
173       val sprintf : ('a, unit, string) Pervasives.format -> 'a
174
175       Same as Printf.fprintf , but instead of printing on an output  channel,
176       return a string containing the result of formatting the arguments.
177
178
179
180
181       val bprintf : Buffer.t -> ('a, Buffer.t, unit) Pervasives.format -> 'a
182
183       Same  as Printf.fprintf , but instead of printing on an output channel,
184       append the formatted arguments to the given extensible buffer (see mod‐
185       ule Buffer ).
186
187
188
189
190
191       === Formatted output functions with continuations. ===
192
193
194       val kfprintf : (Pervasives.out_channel -> 'a) -> Pervasives.out_channel
195       -> ('b, Pervasives.out_channel, unit, 'a) Pervasives.format4 -> 'b
196
197       Same as fprintf , but instead of returning immediately, passes the  out
198       channel to its first argument at the end of printing.
199
200
201
202
203       val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) Pervasives.for‐
204       mat4 -> 'b
205
206       Same as sprintf above, but instead of returning the string,  passes  it
207       to the first argument.
208
209
210
211
212       val kbprintf : (Buffer.t -> 'a) -> Buffer.t -> ('b, Buffer.t, unit, 'a)
213       Pervasives.format4 -> 'b
214
215       Same as bprintf , but instead of returning immediately, passes the buf‐
216       fer to its first argument at the end of printing.
217
218
219
220
221       val  kprintf : (string -> 'a) -> ('b, unit, string, 'a) Pervasives.for‐
222       mat4 -> 'b
223
224       A deprecated synonym for ksprintf .
225
226
227
228
229
230
231OCamldoc                          2017-03-22                         Printf(3)
Impressum