1*946379e7SchristosThis is autosprintf.info, produced by makeinfo version 4.8 from 2*946379e7Schristosautosprintf.texi. 3*946379e7Schristos 4*946379e7SchristosINFO-DIR-SECTION C++ libraries 5*946379e7SchristosSTART-INFO-DIR-ENTRY 6*946379e7Schristos* autosprintf: (autosprintf). Support for printf format strings in C++. 7*946379e7SchristosEND-INFO-DIR-ENTRY 8*946379e7Schristos 9*946379e7Schristos This file provides documentation for GNU `autosprintf' library. 10*946379e7Schristos 11*946379e7Schristos Copyright (C) 2002-2003 Free Software Foundation, Inc. 12*946379e7Schristos 13*946379e7Schristos This manual is free documentation. It is dually licensed under the 14*946379e7SchristosGNU FDL and the GNU GPL. This means that you can redistribute this 15*946379e7Schristosmanual under either of these two licenses, at your choice. 16*946379e7Schristos 17*946379e7Schristos This manual is covered by the GNU FDL. Permission is granted to 18*946379e7Schristoscopy, distribute and/or modify this document under the terms of the GNU 19*946379e7SchristosFree Documentation License (FDL), either version 1.2 of the License, or 20*946379e7Schristos(at your option) any later version published by the Free Software 21*946379e7SchristosFoundation (FSF); with no Invariant Sections, with no Front-Cover Text, 22*946379e7Schristosand with no Back-Cover Texts. A copy of the license is at 23*946379e7Schristos`http://www.gnu.org/licenses/fdl.html'. 24*946379e7Schristos 25*946379e7Schristos This manual is covered by the GNU GPL. You can redistribute it 26*946379e7Schristosand/or modify it under the terms of the GNU General Public License 27*946379e7Schristos(GPL), either version 2 of the License, or (at your option) any later 28*946379e7Schristosversion published by the Free Software Foundation (FSF). A copy of the 29*946379e7Schristoslicense is at `http://www.gnu.org/licenses/gpl.html'. 30*946379e7Schristos 31*946379e7Schristos 32*946379e7SchristosFile: autosprintf.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) 33*946379e7Schristos 34*946379e7SchristosGNU autosprintf 35*946379e7Schristos*************** 36*946379e7Schristos 37*946379e7SchristosThis manual documents the GNU autosprintf class, version 1.0. 38*946379e7Schristos 39*946379e7Schristos* Menu: 40*946379e7Schristos 41*946379e7Schristos* Introduction:: Introduction 42*946379e7Schristos* Class autosprintf:: The `autosprintf' class 43*946379e7Schristos* Using autosprintf:: Using `autosprintf' in own programs 44*946379e7Schristos 45*946379e7Schristos 46*946379e7SchristosFile: autosprintf.info, Node: Introduction, Next: Class autosprintf, Prev: Top, Up: Top 47*946379e7Schristos 48*946379e7Schristos1 Introduction 49*946379e7Schristos************** 50*946379e7Schristos 51*946379e7SchristosThis package makes the C formatted output routines (`fprintf' et al.) 52*946379e7Schristosusable in C++ programs, for use with the `<string>' strings and the 53*946379e7Schristos`<iostream>' streams. 54*946379e7Schristos 55*946379e7Schristos It allows to write code like 56*946379e7Schristos 57*946379e7Schristos cerr << autosprintf ("syntax error in %s:%d: %s", filename, line, errstring); 58*946379e7Schristos 59*946379e7Schristosinstead of 60*946379e7Schristos 61*946379e7Schristos cerr << "syntax error in " << filename << ":" << line << ": " << errstring; 62*946379e7Schristos 63*946379e7Schristos The benefits of the autosprintf syntax are: 64*946379e7Schristos 65*946379e7Schristos * It reuses the standard POSIX printf facility. Easy migration from 66*946379e7Schristos C to C++. 67*946379e7Schristos 68*946379e7Schristos * English sentences are kept together. 69*946379e7Schristos 70*946379e7Schristos * It makes internationalization possible. Internationalization 71*946379e7Schristos requires format strings, because in some cases the translator 72*946379e7Schristos needs to change the order of a sentence, and more generally it is 73*946379e7Schristos easier for the translator to work with a single string for a 74*946379e7Schristos sentence than with multiple string pieces. 75*946379e7Schristos 76*946379e7Schristos * It reduces the risk of programming errors due to forgotten state 77*946379e7Schristos in the output stream (e.g. `cout << hex;' not followed by `cout << 78*946379e7Schristos dec;'). 79*946379e7Schristos 80*946379e7Schristos 81*946379e7SchristosFile: autosprintf.info, Node: Class autosprintf, Next: Using autosprintf, Prev: Introduction, Up: Top 82*946379e7Schristos 83*946379e7Schristos2 The `autosprintf' class 84*946379e7Schristos************************* 85*946379e7Schristos 86*946379e7SchristosAn instance of class `autosprintf' just contains a string with the 87*946379e7Schristosformatted output result. Such an instance is usually allocated as an 88*946379e7Schristosautomatic storage variable, i.e. on the stack, not with `new' on the 89*946379e7Schristosheap. 90*946379e7Schristos 91*946379e7Schristos The constructor `autosprintf (const char *format, ...)' takes a 92*946379e7Schristosformat string and additional arguments, like the C function `printf'. 93*946379e7Schristos 94*946379e7Schristos Conversions to `char *' and `std::string' are defined that return 95*946379e7Schristosthe encapsulated string. 96*946379e7Schristos 97*946379e7Schristos The destructor `~autosprintf ()' destroys the encapsulated string. 98*946379e7Schristos 99*946379e7Schristos An `operator <<' is provided that outputs the encapsulated string to 100*946379e7Schristosthe given `ostream'. 101*946379e7Schristos 102*946379e7Schristos 103*946379e7SchristosFile: autosprintf.info, Node: Using autosprintf, Prev: Class autosprintf, Up: Top 104*946379e7Schristos 105*946379e7Schristos3 Using `autosprintf' in own programs 106*946379e7Schristos************************************* 107*946379e7Schristos 108*946379e7SchristosTo use the `autosprintf' class in your programs, you need to add 109*946379e7Schristos 110*946379e7Schristos #include "autosprintf.h" 111*946379e7Schristos using gnu::autosprintf; 112*946379e7Schristos 113*946379e7Schristosto your source code. The include file defines the class `autosprintf', 114*946379e7Schristosin a namespace called `gnu'. The `using' statement makes it possible to 115*946379e7Schristosuse the class without the (otherwise natural) `gnu::' prefix. 116*946379e7Schristos 117*946379e7Schristos When linking your program, you need to link with `libasprintf', 118*946379e7Schristosbecause that's where the class is defined. In projects using GNU 119*946379e7Schristos`autoconf', this means adding `AC_LIB_LINKFLAGS([asprintf])' to 120*946379e7Schristos`configure.in' or `configure.ac', and using the @LIBASPRINTF@ Makefile 121*946379e7Schristosvariable that it provides. 122*946379e7Schristos 123*946379e7Schristos 124*946379e7Schristos 125*946379e7SchristosTag Table: 126*946379e7SchristosNode: Top1336 127*946379e7SchristosNode: Introduction1696 128*946379e7SchristosNode: Class autosprintf2847 129*946379e7SchristosNode: Using autosprintf3619 130*946379e7Schristos 131*946379e7SchristosEnd Tag Table 132