This package makes the C formatted output routines (fprintf et al.) usable in C++ programs, for use with the <string> strings and the <iostream> streams.
It allows to write code like:
cerr << autosprintf ("syntax error in %s:%d: %s", filename, line, errstring);
instead of:
cerr << "syntax error in " << filename << ":" << line << ": " << errstring;
Benefits:
printf facility. Easy migration from C to C++.cout << hex; without cout << dec;).| Use Case | Command | Description |
|---|---|---|
| 📝 Format a string with printf-like syntax | autosprintf(format, ...) | Returns a std::string with formatted output. |
| 🔗 Output to stream | stream << autosprintf(...) | Uses operator<< to insert formatted string into an ostream. |
| 📄 Convert to C string | (char *)autosprintf(...) | Returns a freshly allocated copy (must be freed with delete[]). |
| 🔧 Include in source | #include "autosprintf.h" | Include the class definition. |
| 🔗 Use namespace | using gnu::autosprintf; | Allows use without gnu:: prefix. |
| 📦 Link with library | -lasprintf or @LIBASPRINTF@ | Link against libasprintf. |
An instance of class autosprintf just contains a string with the formatted output result. Such an instance is usually allocated as an automatic storage variable (on the stack), not with new on the heap.
autosprintf (const char *format, ...) — takes a format string and additional arguments, like C printf.char * — returns a freshly allocated copy (must be freed with delete[]).std::string — returns a copy with automatic memory management.~autosprintf () — destroys the encapsulated string.operator << — outputs the encapsulated string to the given ostream.To use the autosprintf class, add to your source code:
#include "autosprintf.h"
using gnu::autosprintf;
The include file defines the class in namespace gnu. The using statement allows use without the gnu:: prefix.
When linking, link with libasprintf. In projects using GNU autoconf, add AC_LIB_LINKFLAGS([asprintf]) to configure.in or configure.ac, and use the @LIBASPRINTF@ Makefile variable.
The files of this package are covered by the licenses indicated in each particular file or directory. Summary:
Version 2.1, February 1999. Copyright (C) 1991, 1999 Free Software Foundation, Inc.
This is the first released version of the Lesser GPL. It is the successor of the GNU Library Public License, version 2.
Full license text: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
Version 2, June 1991. Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Full license text: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Version 1.2, November 2002. Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
Full license text: https://www.gnu.org/licenses/old-licenses/fdl-1.2.html
Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-14 20:33 @2600:1f28:365:80b0:4d23:66fa:c2bb:7bae
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)