Where can I find the equivalent of “printf” in Ada?
While the standard package Text_IO provides many features, the request for a printf-like function is not unusual. (solution based on a suggestion by Tucker Taft) It is possible to produce a printf-like capability by overloading the “&” operator to take an object of type Format and an object of some type and return the Format, properly advanced, after having performed the appropriate output. The remaining format can be converted back to a string–e.g. to examine what is left at the end of the format string– or simply printed to display whatever remains at the end.
While the standard package Text_IO provides many features, the request for a printf-like function is not unusual.(solution based on a suggestion by Tucker Taft)It is possible to produce a printf-like capability by overloading the “&” operator to take an object of type Format and an object of some type and return the Format, properly advanced, after having performed the appropriate output. The remaining format can be converted back to a string–e.g. to examine what is left at the end of the format string– or simply printed to display whatever remains at the end.
While the standard package Text_IO provides many features, the request for a printf-like function is not unusual. (solution based on a suggestion by Tucker Taft) It is possible to produce a printf-like capability by overloading the “&” operator to take an object of type Format and an object of some type and return the Format, properly advanced, after having performed the appropriate output. The remaining format can be converted back to a string–e.g. to examine what is left at the end of the format string– or simply printed to display whatever remains at the end. For example: with Text_IO; package Formatted_Output is type Format is limited private; function Fmt (Str : String) return Format; function “&” (Left : Format; Right : Integer) return Format; function “&” (Left : Format; Right : Float) return Format; function “&” (Left : Format; Right : String) return Format; … — other overloadings of “&” procedure Print (Fmt : Format); function To_String (Fmt : Format) return String; priva