1This is autosprintf.info, produced by makeinfo version 4.6 from 2autosprintf.texi. 3 4INFO-DIR-SECTION C++ libraries 5START-INFO-DIR-ENTRY 6* autosprintf: (autosprintf). Support for printf format strings in C++. 7END-INFO-DIR-ENTRY 8 9 This file provides documentation for GNU `autosprintf' library. 10 11 Copyright (C) 2002 Free Software Foundation, Inc. 12 13 Permission is granted to make and distribute verbatim copies of this 14manual provided the copyright notice and this permission notice are 15preserved on all copies. 16 17 Permission is granted to copy and distribute modified versions of 18this manual under the conditions for verbatim copying, provided that 19the entire resulting derived work is distributed under the terms of a 20permission notice identical to this one. 21 22 Permission is granted to copy and distribute translations of this 23manual into another language, under the above conditions for modified 24versions, except that this permission notice may be stated in a 25translation approved by the Foundation. 26 27 28File: autosprintf.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) 29 30GNU autosprintf 31*************** 32 33This manual documents the GNU autosprintf class, version 1.0. 34 35* Menu: 36 37* Introduction:: Introduction 38* Class autosprintf:: The `autosprintf' class 39* Using autosprintf:: Using `autosprintf' in own programs 40 41 42File: autosprintf.info, Node: Introduction, Next: Class autosprintf, Prev: Top, Up: Top 43 44Introduction 45************ 46 47This package makes the C formatted output routines (`fprintf' et al.) 48usable in C++ programs, for use with the `<string>' strings and the 49`<iostream>' streams. 50 51 It allows to write code like 52 53 cerr << autosprintf ("syntax error in %s:%d: %s", filename, line, errstring); 54 55instead of 56 57 cerr << "syntax error in " << filename << ":" << line << ": " << errstring; 58 59 The benefits of the autosprintf syntax are: 60 61 * It reuses the standard POSIX printf facility. Easy migration from 62 C to C++. 63 64 * English sentences are kept together. 65 66 * It makes internationalization possible. Internationalization 67 requires format strings, because in some cases the translator 68 needs to change the order of a sentence, and more generally it is 69 easier for the translator to work with a single string for a 70 sentence than with multiple string pieces. 71 72 * It reduces the risk of programming errors due to forgotten state 73 in the output stream (e.g. `cout << hex;' not followed by `cout << 74 dec;'). 75 76 77File: autosprintf.info, Node: Class autosprintf, Next: Using autosprintf, Prev: Introduction, Up: Top 78 79The `autosprintf' class 80*********************** 81 82An instance of class `autosprintf' just contains a string with the 83formatted output result. Such an instance is usually allocated as an 84automatic storage variable, i.e. on the stack, not with `new' on the 85heap. 86 87 The constructor `autosprintf (const char *format, ...)' takes a 88format string and additional arguments, like the C function `printf'. 89 90 Conversions to `char *' and `std::string' are defined that return 91the encapsulated string. 92 93 The destructor `~autosprintf ()' destroys the encapsulated string. 94 95 An `operator <<' is provided that outputs the encapsulated string to 96the given `ostream'. 97 98 99File: autosprintf.info, Node: Using autosprintf, Prev: Class autosprintf, Up: Top 100 101Using `autosprintf' in own programs 102*********************************** 103 104To use the `autosprintf' class in your programs, you need to add 105 106 #include "autosprintf.h" 107 using gnu::autosprintf; 108 109to your source code. The include file defines the class `autosprintf', 110in a namespace called `gnu'. The `using' statement makes it possible to 111use the class without the (otherwise natural) `gnu::' prefix. 112 113 When linking your program, you need to link with `libasprintf', 114because that's where the class is defined. In projects using GNU 115`autoconf', this means adding `AC_LIB_LINKFLAGS([asprintf])' to 116`configure.in' or `configure.ac', and using the @LIBASPRINTF@ Makefile 117variable that it provides. 118 119 120 121Tag Table: 122Node: Top1011 123Node: Introduction1371 124Node: Class autosprintf2518 125Node: Using autosprintf3286 126 127End Tag Table 128