1
This is autosprintf.info, produced by makeinfo version 4.6 from
4
INFO-DIR-SECTION C++ libraries
6
* autosprintf: (autosprintf). Support for printf format strings in C++.
9
This file provides documentation for GNU `autosprintf' library.
11
Copyright (C) 2002 Free Software Foundation, Inc.
13
Permission is granted to make and distribute verbatim copies of this
14
manual provided the copyright notice and this permission notice are
15
preserved on all copies.
17
Permission is granted to copy and distribute modified versions of
18
this manual under the conditions for verbatim copying, provided that
19
the entire resulting derived work is distributed under the terms of a
20
permission notice identical to this one.
22
Permission is granted to copy and distribute translations of this
23
manual into another language, under the above conditions for modified
24
versions, except that this permission notice may be stated in a
25
translation approved by the Foundation.
28
File: autosprintf.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
33
This manual documents the GNU autosprintf class, version 1.0.
37
* Introduction:: Introduction
38
* Class autosprintf:: The `autosprintf' class
39
* Using autosprintf:: Using `autosprintf' in own programs
42
File: autosprintf.info, Node: Introduction, Next: Class autosprintf, Prev: Top, Up: Top
47
This package makes the C formatted output routines (`fprintf' et al.)
48
usable in C++ programs, for use with the `<string>' strings and the
51
It allows to write code like
53
cerr << autosprintf ("syntax error in %s:%d: %s", filename, line, errstring);
57
cerr << "syntax error in " << filename << ":" << line << ": " << errstring;
59
The benefits of the autosprintf syntax are:
61
* It reuses the standard POSIX printf facility. Easy migration from
64
* English sentences are kept together.
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.
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 <<
77
File: autosprintf.info, Node: Class autosprintf, Next: Using autosprintf, Prev: Introduction, Up: Top
79
The `autosprintf' class
80
***********************
82
An instance of class `autosprintf' just contains a string with the
83
formatted output result. Such an instance is usually allocated as an
84
automatic storage variable, i.e. on the stack, not with `new' on the
87
The constructor `autosprintf (const char *format, ...)' takes a
88
format string and additional arguments, like the C function `printf'.
90
Conversions to `char *' and `std::string' are defined that return
91
the encapsulated string.
93
The destructor `~autosprintf ()' destroys the encapsulated string.
95
An `operator <<' is provided that outputs the encapsulated string to
99
File: autosprintf.info, Node: Using autosprintf, Prev: Class autosprintf, Up: Top
101
Using `autosprintf' in own programs
102
***********************************
104
To use the `autosprintf' class in your programs, you need to add
106
#include "autosprintf.h"
107
using gnu::autosprintf;
109
to your source code. The include file defines the class `autosprintf',
110
in a namespace called `gnu'. The `using' statement makes it possible to
111
use the class without the (otherwise natural) `gnu::' prefix.
113
When linking your program, you need to link with `libasprintf',
114
because 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
117
variable that it provides.
123
Node: Introduction1371
124
Node: Class autosprintf2518
125
Node: Using autosprintf3286