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

NAME

6       Stdlib.Printf - no description
7

Module

9       Module   Stdlib.Printf
10

Documentation

12       Module Printf
13        : (module Stdlib__printf)
14
15
16
17
18
19
20
21
22       val fprintf : out_channel -> ('a, out_channel, unit) format -> 'a
23
24
25       fprintf outchan format arg1 ... argN formats the arguments arg1 to argN
26       according to the format string  format  ,  and  outputs  the  resulting
27       string on the channel outchan .
28
29       The  format  string  is  a character string which contains two types of
30       objects: plain characters, which are simply copied to the output  chan‐
31       nel, and conversion specifications, each of which causes conversion and
32       printing of arguments.
33
34       Conversion specifications have the following form:
35
36
37       % [flags] [width] [.precision] type
38
39       In short, a conversion specification consists in the % character,  fol‐
40       lowed  by  optional  modifiers  and  a type which is made of one or two
41       characters.
42
43       The types and their meanings are:
44
45
46       - d , i : convert an integer argument to signed decimal.   The  flag  #
47       adds underscores to large values for readability.
48
49       -  u , n , l , L , or N : convert an integer argument to unsigned deci‐
50       mal.  Warning: n , l , L , and N are used for scanf , and should not be
51       used  for  printf  .   The  flag # adds underscores to large values for
52       readability.
53
54       - x : convert an integer argument to unsigned hexadecimal, using lower‐
55       case letters.  The flag # adds a 0x prefix to non zero values.
56
57       - X : convert an integer argument to unsigned hexadecimal, using upper‐
58       case letters.  The flag # adds a 0X prefix to non zero values.
59
60       - o : convert an integer argument to unsigned octal.  The flag # adds a
61       0 prefix to non zero values.
62
63       - s : insert a string argument.
64
65       -  S  :  convert  a  string  argument  to  OCaml syntax (double quotes,
66       escapes).
67
68       - c : insert a character argument.
69
70       - C : convert a character argument  to  OCaml  syntax  (single  quotes,
71       escapes).
72
73       -  f  :  convert  a floating-point argument to decimal notation, in the
74       style dddd.ddd .
75
76       - F : convert a floating-point argument to OCaml  syntax  (  dddd.   or
77       dddd.ddd  or  d.ddd  e+-dd  ).  Converts to hexadecimal with the # flag
78       (see h ).
79
80       - e or E : convert a floating-point argument to  decimal  notation,  in
81       the style d.ddd e+-dd (mantissa and exponent).
82
83       -  g  or  G : convert a floating-point argument to decimal notation, in
84       style f or e , E (whichever is more compact).  Moreover,  any  trailing
85       zeros  are removed from the fractional part of the result and the deci‐
86       mal-point character is removed if there is no fractional  part  remain‐
87       ing.
88
89       -  h  or H : convert a floating-point argument to hexadecimal notation,
90       in the style 0xh.hhhh p+-dd (hexadecimal mantissa, exponent in  decimal
91       and denotes a power of 2).
92
93       - B : convert a boolean argument to the string true or false
94
95
96       -  b  :  convert a boolean argument (deprecated; do not use in new pro‐
97       grams).
98
99       - ld , li , lu , lx , lX , lo : convert an int32 argument to the format
100       specified by the second letter (decimal, hexadecimal, etc).
101
102       -  nd  ,  ni  , nu , nx , nX , no : convert a nativeint argument to the
103       format specified by the second letter.
104
105       - Ld , Li , Lu , Lx , LX , Lo : convert an int64 argument to the format
106       specified by the second letter.
107
108       -  a : user-defined printer. Take two arguments and apply the first one
109       to outchan (the current output channel) and to the second argument. The
110       first  argument  must therefore have type out_channel -> 'b -> unit and
111       the second 'b .  The output produced by the function is inserted in the
112       output of fprintf at the current point.
113
114       - t : same as %a , but take only one argument (with type out_channel ->
115       unit ) and apply it to outchan .
116
117       - { fmt %} : convert a format string argument to its type digest.   The
118       argument must have the same type as the internal format string fmt .
119
120       -  ( fmt %) : format string substitution. Take a format string argument
121       and substitute it to the internal format string fmt to print  following
122       arguments.  The argument must have the same type as the internal format
123       string fmt .
124
125       - !  : take no argument and flush the output.
126
127       - % : take no argument and output one % character.
128
129       - @ : take no argument and output one @ character.
130
131       - , : take no argument and output nothing: a no-op delimiter  for  con‐
132       version specifications.
133
134       The optional flags are:
135
136       - - : left-justify the output (default is right justification).
137
138       - 0 : for numerical conversions, pad with zeroes instead of spaces.
139
140       -  + : for signed numerical conversions, prefix number with a + sign if
141       positive.
142
143       -space: for signed numerical conversions, prefix number with a space if
144       positive.
145
146       -  #  : request an alternate formatting style for the integer types and
147       the floating-point type F .
148
149       The optional width is an integer indicating the minimal  width  of  the
150       result.  For  instance, %6d prints an integer, prefixing it with spaces
151       to fill at least 6 characters.
152
153       The optional precision is a dot .  followed by  an  integer  indicating
154       how many digits follow the decimal point in the %f , %e , %E , %h , and
155       %H conversions or the maximum number of significant  digits  to  appear
156       for  the %F , %g and %G conversions.  For instance, %.4f prints a float
157       with 4 fractional digits.
158
159       The integer in a width or precision can also be specified  as  *  ,  in
160       which  case  an  extra  integer argument is taken to specify the corre‐
161       sponding width or precision . This integer  argument  precedes  immedi‐
162       ately the argument to print.  For instance, %.*f prints a float with as
163       many fractional digits as the value of the argument  given  before  the
164       float.
165
166
167
168       val printf : ('a, out_channel, unit) format -> 'a
169
170       Same as Printf.fprintf , but output on stdout .
171
172
173
174       val eprintf : ('a, out_channel, unit) format -> 'a
175
176       Same as Printf.fprintf , but output on stderr .
177
178
179
180       val sprintf : ('a, unit, string) format -> 'a
181
182       Same  as Printf.fprintf , but instead of printing on an output channel,
183       return a string containing the result of formatting the arguments.
184
185
186
187       val bprintf : Buffer.t -> ('a, Buffer.t, unit) format -> 'a
188
189       Same as Printf.fprintf , but instead of printing on an output  channel,
190       append the formatted arguments to the given extensible buffer (see mod‐
191       ule Buffer ).
192
193
194
195       val ifprintf : 'b -> ('a, 'b, 'c, unit) format4 -> 'a
196
197       Same as Printf.fprintf , but does not print anything.  Useful to ignore
198       some material when conditionally printing.
199
200
201       Since 3.10.0
202
203
204
205       val ibprintf : Buffer.t -> ('a, Buffer.t, unit) format -> 'a
206
207       Same as Printf.bprintf , but does not print anything.  Useful to ignore
208       some material when conditionally printing.
209
210
211       Since 4.11.0
212
213
214
215
216       Formatted output functions with continuations.
217
218       val kfprintf : (out_channel -> 'd) -> out_channel -> ('a,  out_channel,
219       unit, 'd) format4 -> 'a
220
221       Same  as fprintf , but instead of returning immediately, passes the out
222       channel to its first argument at the end of printing.
223
224
225       Since 3.09.0
226
227
228
229       val ikfprintf : ('b -> 'd) -> 'b -> ('a, 'b, 'c, 'd) format4 -> 'a
230
231       Same as kfprintf above, but does not print anything.  Useful to  ignore
232       some material when conditionally printing.
233
234
235       Since 4.01.0
236
237
238
239       val ksprintf : (string -> 'd) -> ('a, unit, string, 'd) format4 -> 'a
240
241       Same  as  sprintf above, but instead of returning the string, passes it
242       to the first argument.
243
244
245       Since 3.09.0
246
247
248
249       val kbprintf : (Buffer.t -> 'd) -> Buffer.t -> ('a, Buffer.t, unit, 'd)
250       format4 -> 'a
251
252       Same as bprintf , but instead of returning immediately, passes the buf‐
253       fer to its first argument at the end of printing.
254
255
256       Since 3.10.0
257
258
259
260       val ikbprintf : (Buffer.t -> 'd) -> Buffer.t ->  ('a,  Buffer.t,  unit,
261       'd) format4 -> 'a
262
263       Same  as kbprintf above, but does not print anything.  Useful to ignore
264       some material when conditionally printing.
265
266
267       Since 4.11.0
268
269
270
271
272       Deprecated
273
274       val kprintf : (string -> 'b) -> ('a, unit, string, 'b) format4 -> 'a
275
276       A deprecated synonym for ksprintf .
277
278
279
280
281
282OCamldoc                          2020-09-01                  Stdlib.Printf(3)
Impressum