4 ms·
std::string formatted_str = std::format( "My name is {} and my favorite number is {}", name, num);
by coldtea 3y ago
std::string formatted_str = std::format(
"My name is {} and my favorite number is {}", name,
num);
- 0xffff2 3y agoThat's really nothing like python strings, which for the same string would be formatted_str = f"My name is {name} and my favorite number is {num}" The function call I could forgive, but the the ability to embed arbitrary python expressions into the f-string directly is a huge readability win IMO.
- interroboink 3y agoMeanwhile Perl's over here like "we had this in the 90s!" (: eg: perl -e '$x="AAA"; print "lowercase: ${\( lc($x) )}\n"'
- gpderetta 3y agoOf course posix shells gad that even before. How far we can go? What's the first language that had something that resembles string interpolation?
- interroboink 3y agoI'm sure someone here can say something about Lisp machines (:
- coldtea 3y agoWell, if that's the syntax, I'd rather not have it!
- coldtea 3y agoThat type of interpolation is something most non-scripting languages don't have anyway, and it took Python several decades to get it, and only has had it in the 5 years or so.