std::string formatting like sprintf

Modern C++ makes this super simple. C++20 C++20 introduces std::format, which allows you to do exactly that. It uses replacement fields similar to those in python: Code from cppreference.com, CC BY-SA and GFDL Check out the compiler support page to see if it’s available in your standard library implementation. As of 2021-11-28, full support is only available in Visual Studio 2019 16.10, which … Read more

How to trim a std::string?

EDIT Since c++17, some parts of the standard library were removed. Fortunately, starting with c++11, we have lambdas which are a superior solution. Thanks to https://stackoverflow.com/a/44973498/524503 for bringing up the modern solution. Original answer: I tend to use one of these 3 for my trimming needs: They are fairly self-explanatory and work very well. EDIT: BTW, I have std::ptr_fun in … Read more

convert a char* to std::string

std::string has a constructor for this: Note that this construct deep copies the character list at s and s should not be nullptr, or else behavior is undefined.