.TH "Printf" 3o source: 2017-09-14 OCamldoc "OCaml library" .SH NAME Printf \- Formatted output functions. .SH Module Module Printf .SH Documentation .sp Module .BI "Printf" : .B sig end .sp Formatted output functions\&. .sp .sp .sp .I val fprintf : .B Pervasives.out_channel -> .B ('a, Pervasives.out_channel, unit) Pervasives.format -> 'a .sp .B fprintf outchan format arg1 \&.\&.\&. argN formats the arguments .B arg1 to .B argN according to the format string .B format , and outputs the resulting string on the channel .B outchan \&. .sp The format string is a character string which contains two types of objects: plain characters, which are simply copied to the output channel, and conversion specifications, each of which causes conversion and printing of arguments\&. .sp Conversion specifications have the following form: .sp .B % [flags] [width] [\&.precision] type .sp In short, a conversion specification consists in the .B % character, followed by optional modifiers and a type which is made of one or two characters\&. .sp The types and their meanings are: .sp .sp \- .B d , .B i : convert an integer argument to signed decimal\&. .sp \- .B u , .B n , .B l , .B L , or .B N : convert an integer argument to unsigned decimal\&. Warning: .B n , .B l , .B L , and .B N are used for .B scanf , and should not be used for .B printf \&. .sp \- .B x : convert an integer argument to unsigned hexadecimal, using lowercase letters\&. .sp \- .B X : convert an integer argument to unsigned hexadecimal, using uppercase letters\&. .sp \- .B o : convert an integer argument to unsigned octal\&. .sp \- .B s : insert a string argument\&. .sp \- .B S : convert a string argument to OCaml syntax (double quotes, escapes)\&. .sp \- .B c : insert a character argument\&. .sp \- .B C : convert a character argument to OCaml syntax (single quotes, escapes)\&. .sp \- .B f : convert a floating\-point argument to decimal notation, in the style .B dddd\&.ddd \&. .sp \- .B F : convert a floating\-point argument to OCaml syntax ( .B dddd\&. or .B dddd\&.ddd or .B d\&.ddd e+\-dd )\&. .sp \- .B e or .B E : convert a floating\-point argument to decimal notation, in the style .B d\&.ddd e+\-dd (mantissa and exponent)\&. .sp \- .B g or .B G : convert a floating\-point argument to decimal notation, in style .B f or .B e , .B E (whichever is more compact)\&. .sp \- .B h or .B H : convert a floating\-point argument to hexadecimal notation, in the style .B 0xh\&.hhhh e+\-dd (hexadecimal mantissa, exponent in decimal and denotes a power of 2)\&. .sp \- .B B : convert a boolean argument to the string .B true or .B false .sp \- .B b : convert a boolean argument (deprecated; do not use in new programs)\&. .sp \- .B ld , .B li , .B lu , .B lx , .B lX , .B lo : convert an .B int32 argument to the format specified by the second letter (decimal, hexadecimal, etc)\&. .sp \- .B nd , .B ni , .B nu , .B nx , .B nX , .B no : convert a .B nativeint argument to the format specified by the second letter\&. .sp \- .B Ld , .B Li , .B Lu , .B Lx , .B LX , .B Lo : convert an .B int64 argument to the format specified by the second letter\&. .sp \- .B a : user\-defined printer\&. Take two arguments and apply the first one to .B outchan (the current output channel) and to the second argument\&. The first argument must therefore have type .B out_channel \-> \&'b \-> unit and the second .B \&'b \&. The output produced by the function is inserted in the output of .B fprintf at the current point\&. .sp \- .B t : same as .B %a , but take only one argument (with type .B out_channel \-> unit ) and apply it to .B outchan \&. .sp \- .B { fmt %} : convert a format string argument to its type digest\&. The argument must have the same type as the internal format string .B fmt \&. .sp \- .B ( fmt %) : format string substitution\&. Take a format string argument and substitute it to the internal format string .B fmt to print following arguments\&. The argument must have the same type as the internal format string .B fmt \&. .sp \- .B ! : take no argument and flush the output\&. .sp \- .B % : take no argument and output one .B % character\&. .sp \- .B @ : take no argument and output one .B @ character\&. .sp \- .B , : take no argument and output nothing: a no\-op delimiter for conversion specifications\&. The optional .B flags are: .sp \- .B \- : left\-justify the output (default is right justification)\&. .sp \- .B 0 : for numerical conversions, pad with zeroes instead of spaces\&. .sp \- .B + : for signed numerical conversions, prefix number with a .B + sign if positive\&. .sp \-space: for signed numerical conversions, prefix number with a space if positive\&. .sp \- .B # : request an alternate formatting style for the hexadecimal and octal integer types ( .B x , .B X , .B o , .B lx , .B lX , .B lo , .B Lx , .B LX , .B Lo )\&. The optional .B width is an integer indicating the minimal width of the result\&. For instance, .B %6d prints an integer, prefixing it with spaces to fill at least 6 characters\&. .sp The optional .B precision is a dot .B \&. followed by an integer indicating how many digits follow the decimal point in the .B %f , .B %e , and .B %E conversions\&. For instance, .B %\&.4f prints a .B float with 4 fractional digits\&. .sp The integer in a .B width or .B precision can also be specified as .B * , in which case an extra integer argument is taken to specify the corresponding .B width or .B precision \&. This integer argument precedes immediately the argument to print\&. For instance, .B %\&.*f prints a .B float with as many fractional digits as the value of the argument given before the float\&. .sp .I val printf : .B ('a, Pervasives.out_channel, unit) Pervasives.format -> 'a .sp Same as .B Printf\&.fprintf , but output on .B stdout \&. .sp .I val eprintf : .B ('a, Pervasives.out_channel, unit) Pervasives.format -> 'a .sp Same as .B Printf\&.fprintf , but output on .B stderr \&. .sp .I val sprintf : .B ('a, unit, string) Pervasives.format -> 'a .sp Same as .B Printf\&.fprintf , but instead of printing on an output channel, return a string containing the result of formatting the arguments\&. .sp .I val bprintf : .B Buffer.t -> ('a, Buffer.t, unit) Pervasives.format -> 'a .sp Same as .B Printf\&.fprintf , but instead of printing on an output channel, append the formatted arguments to the given extensible buffer (see module .B Buffer )\&. .sp .I val ifprintf : .B 'b -> ('a, 'b, 'c, unit) Pervasives.format4 -> 'a .sp Same as .B Printf\&.fprintf , but does not print anything\&. Useful to ignore some material when conditionally printing\&. .sp .B "Since" 3.10.0 .sp .PP .B === Formatted output functions with continuations\&. === .PP .I val kfprintf : .B (Pervasives.out_channel -> 'd) -> .B Pervasives.out_channel -> .B ('a, Pervasives.out_channel, unit, 'd) Pervasives.format4 -> 'a .sp Same as .B fprintf , but instead of returning immediately, passes the out channel to its first argument at the end of printing\&. .sp .B "Since" 3.09.0 .sp .I val ikfprintf : .B ('b -> 'd) -> 'b -> ('a, 'b, 'c, 'd) Pervasives.format4 -> 'a .sp Same as .B kfprintf above, but does not print anything\&. Useful to ignore some material when conditionally printing\&. .sp .B "Since" 4.01.0 .sp .I val ksprintf : .B (string -> 'd) -> ('a, unit, string, 'd) Pervasives.format4 -> 'a .sp Same as .B sprintf above, but instead of returning the string, passes it to the first argument\&. .sp .B "Since" 3.09.0 .sp .I val kbprintf : .B (Buffer.t -> 'd) -> .B Buffer.t -> ('a, Buffer.t, unit, 'd) Pervasives.format4 -> 'a .sp Same as .B bprintf , but instead of returning immediately, passes the buffer to its first argument at the end of printing\&. .sp .B "Since" 3.10.0 .sp .PP .B === Deprecated === .PP .I val kprintf : .B (string -> 'b) -> ('a, unit, string, 'b) Pervasives.format4 -> 'a .sp A deprecated synonym for .B ksprintf \&. .sp