Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
177 views

How boost format works in terms of c++?

I was looking at boost::format documents and just the first example made me wondering: cout << boost::format("writing %1%, x=%2% : %3%-th try") % "toto" % 40.23 % 50; What ...
Roman's user avatar
  • 1,436
1 vote
1 answer
1k views

boost format set maximum precision of floating point

I have essentially the following: typedef TFp double; boost::format fmt("Floating point: %2$f"); TFp v = 0.000000001; fmt % v; std::cout << fmt.str(); As per the boost format manual, this ...
Roel's user avatar
  • 19.6k
1 vote
0 answers
73 views

boost format yield different output for seemingly same strings

Background I am using the boost format library to format some text. My input is an uint8_t array. This is the code I used: #include <array> #include <vector> #include <string> #...
raidensan's user avatar
  • 1,139
0 votes
1 answer
543 views

What's preventing Boost.Format form using my stream operator overload for optional int?

I want to be able to use a std::optional<int> with Boost.Format. #include <iostream> #include <optional> #include <boost/format.hpp> struct SomeType { int x; }; std::...
Chris_F's user avatar
  • 5,517
1 vote
1 answer
647 views

Feeding boost::format with variadic parameters

I am attempting to write a logging function which takes a variadic argument list and prints in a safe manor. vprintf seems like the obvious answer, but I cannot seem to find a safe way to handle when ...
DaBernMon's user avatar
0 votes
1 answer
520 views

boost::format exception under windows only

I already used boost::format in many case but I found one for which the windows implementation doesn't react as I expected because it throw an exception boost::bad_format_string: format-string is ill-...
alexbuisson's user avatar
  • 8,419
7 votes
2 answers
2k views

Why do Boost Format and printf behave differently on same format string

The Boost Format documentation says: One of its goal is to provide a replacement for printf, that means format can parse a format-string designed for printf, apply it to the given arguments, ...
ToBe's user avatar
  • 961
2 votes
2 answers
2k views

Boost::Format with char array

I've looked around and I've been unable to find a solution to storing what is returned from a boost format into a char array. For example: #include "stdafx.h" #include <iostream> #include <...
pistachiobk's user avatar
3 votes
1 answer
560 views

How to create / combine / concatenate boost::format from multiple boost::format

This is given: boost::format greeting("%s (Greeting)"); boost::format name("%s (Name)"); 'greetingwithname' should combine and reuses 'greeting' and 'name' so that it is equivalent to this: boost::...
ToBe's user avatar
  • 961
-2 votes
2 answers
5k views

Error in boost format

When I try to compile in cygwin there are problem like this: fatal error: boost/format.hpp: No such file or directory #include <boost/format.hpp> How I fix this problem, someone please ...
lapan28's user avatar
  • 29
3 votes
1 answer
2k views

Odd behavior in boost::format hex

I'm trying to format a binary array: char* memblock to a hex string. When I use the following: fprintf(out, "0x%02x,", memblock[0]); I get the following output: 0x7f, When I try to use boost::...
Christian Stewart's user avatar
5 votes
2 answers
4k views

How to use boost::format to zeropad a number where the number of decimal places is contained in a variable?

I would like to zeropad a number such that it has 5 digits and get it as a string. This can be done with the following: unsigned int theNumber = 10; std::string theZeropaddedString = (boost::format("...
user3731622's user avatar
  • 5,075
11 votes
3 answers
6k views

boost::format with variadic template arguments

Suppose I have a printf-like function (used for logging) utilizing perfect forwarding: template<typename... Arguments> void awesome_printf(std::string const& fmt, Arguments&&... ...
void.pointer's user avatar
  • 26.2k
26 votes
5 answers
17k views

C++11 Equivalent to Boost.Format

Anything like Boost.Format in the C++11 standard? I've been able to avoid using Boost with a better C++11 option for every other need I've had. For that matter, Boost.Format doesn't hold a candle to ...
Chris Redford's user avatar
0 votes
3 answers
208 views

C++ variable lifetime -- need workaround to return temporary

I have a C++ object (boost::format) that has a str() function which returns an std::string. So when I need a formatted C string, I need to write something like: (boost::format("%1% %2%") % "1" % "2")...
Felix Dombek's user avatar
  • 14.3k
0 votes
1 answer
2k views

C++ how to show exact digits of fraction part

Is there any way in C++ (or boost lib) to show a given number digits of fraction part? But I don't want to print the trailing 0 in fraction part (eg. 1.000, 1.500). See this case: cout << std::...
Stan's user avatar
  • 38.2k
2 votes
2 answers
844 views

Compile-time checking of Boost.Format

Both Clang and GCC can check printf-style functions for mismatches between their format strings and their arguments. For example, they'll complain about statements like this: printf("Hello, %s!\n"); ...
Josh Kelley's user avatar
  • 58.2k
1 vote
2 answers
4k views

A convenient logging statement for C++ using boost::format

I want to design a logging function with the following characteristics: based on std::string rather than char* supports variable number of variables, like printf accepts as first parameter a severity ...
Chap's user avatar
  • 3,835
3 votes
1 answer
4k views

c++ boost format float - how to specify that I do not want . and following zeros

I would like to use boost::format to convert a float number to string. These are several examples for the expected results: 0.5 -> "0.5" 0 -> "0" 1.00001 -> "1" 3.66 -> "3.7" ...
gsf's user avatar
  • 7,192
11 votes
3 answers
10k views

Formatting n significant digits in C++ without scientific notation

I want to format a floating point value to n significant digits but never using scientific notation (even if it would be shorter). The format specification %f doesn't deal in significant digits, and %...
PeteC's user avatar
  • 1,067
5 votes
2 answers
2k views

Printing bools with boost::format as symbolic values?

How do I print boolean values with boost::format as symbolic values? Can this be done without boost::io::group? It seems that flags sent to the stream beforehand get retested: #include <iomanip> ...
Micha Wiedenmann's user avatar
12 votes
2 answers
9k views

Why boost::format cannot be converted directly to std::string? [closed]

Following is not possible: std::string s = boost::format("%d") % 1; // error You have to explicitely call the method str(): std::string s = (boost::format("%d") % 1).str(); // OK It would only be ...
mr_georg's user avatar
  • 3,713
0 votes
2 answers
1k views

VC++ 2012 and Boost incompatibility - `throw()` specifications in library headers

I have a new project where I cannot use boost::format. I get a compiler error complaining that boost's override of a virtual function, ~basic_altstringbuf, lacks a "throw()". Even the most trivial ...
Jive Dadson's user avatar
10 votes
4 answers
2k views

boost::format and custom printing a std containers

I have a function in my namespace ns that helps me print STL containers. For example: template <typename T> std::ostream& operator<<(std::ostream& stream, const std::set<T>&...
Travis Gockel's user avatar
7 votes
1 answer
13k views

Using %s format specifier with boost::format and std::string

I know that using the %s format specifier and std::string like this leads to undefined behaviour: std::string myString = "test"; printf("%s", myString); But is it save to use the same specifier and ...
Ronald McBean's user avatar
0 votes
1 answer
256 views

How do you use a CAtlStringW with boost format?

I tried this: #include <iostream> #include <boost\format.hpp> #include <atlstr.h> std::ostream& operator<<(std::ostream& os, const ATL::CAtlStringW& string) { ...
Scott Langham's user avatar
1 vote
1 answer
121 views

How to cumulate time durations

I am using boost::format variable to get elapsed time in seconds boost::posix_time::time_duration total_time = start_1.elapsed(); long milliseconds = total_time.total_milliseconds(); boost::format ...
saloua's user avatar
  • 2,493
7 votes
1 answer
1k views

Is it possible to use Boost.Format with a preallocated buffer?

I was wondering whether Boost.Format does support using a fixed-width / preallocated buffer as output instead of a dynamic buffer managed by the lib itself? That is, normally you'd do: boost::...
Martin Ba's user avatar
  • 38.7k
3 votes
6 answers
752 views

Real positional string formatting?

(Note: I know of Boost.Format, I'm looking for a better way to do the following.) First a use-case example: In some countries, you name a person by calling his / her surname first and the forename ...
Xeo's user avatar
  • 132k
4 votes
2 answers
2k views

Using boost::format %s specifier with UTF-8 strings

We are adding support for UTF8 to an existing application with a large code base. This application uses boost::format(), and the output in non-ASCII characters is not aligning properly. Specifically,...
Grognard61's user avatar
1 vote
1 answer
735 views

boost::format() output operator

I need to write the class which will accept boost::format() through the operator like cout does: cout << boost::format("some string; some param = %d\n") % someValue; Which type of operator's ...
Slaus's user avatar
  • 2,226
5 votes
2 answers
606 views

Using boost::format in a boost::lambda

For some reason, I fail to use boost::format in a boost::lambda. Here is a (hopefully) compilable simplification of my code : #include <algorithm> #include <iomanip> #include <iostream&...
icecrime's user avatar
  • 76.7k