Abseil C++

An open-source collection of C++ library code designed to augment the C++ standard library

  • Tip of the Week #18: String Formatting with Substitute
    https://abseil.io/tips/18

    Originally posted as TotW #18 on October 4, 2012

    By Titus Winters

    Updated 2022-11-16

    Quicklink: abseil.io/tips/18

    It happens all the time: you’re writing code and suddenly you need to assemble a new string from a template and some run-time values. Maybe it’s an error message from a failed Stubby call, maybe it’s the body of an email being sent from an internal process. Probably the most common mechanism for string formatting outside of google3 is sprintf/snprintf. But as we wander through the codebase, we see many things that people have done, and many places where C++ engineers are spending too much of their time, too many cycles, and too many lines of code to accomplish this task. In this week’s tip, we will walk through some common options and point out their various drawbacks.

    Option (...)