C++20
C++20 introduces format(), so we can do the following.
#include <iostream>
#include <format>
#include <cmath>
int main() {
for(int i=0; i<10; i++) {
double x = pow(2.0,i);
std::cout << std::format("Hello {}! {} {:.03f}\n", "world", i, x);
}
}
Compile with
g++ -o a -std=c++20 a.cpp
(Note the -sdc=c++20 as g++ uses an earlier standard by default.)
Resources
- This stackoverflow