Is it possible to format strings in C++ like python’s f-strings?

C++ doesn’t have reflection. As a result, it is impossible to offer a reference to a variable by its name.

But as @NicolBolas points out, even if reflection was present, there would be more needed. Not only would it require huge language support (telling the called function what the variables were in the calling scope), it would also prevent tons of optimization. The compiler could not remove any variable, as the format string (when not known at compile time) could end up referring to any variable in-scope.

So, no. std::format is the closest.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)