I really liked the answer given in sprintf in c++? but it still isn't quite what I'm looking for.
I want to create a constant string with placeholders, like
const std::string LOGIN_URL = "%s://%s/chronicle/spring/api/logout";
and then build the string with replaceable parameters like:
sprintf(url, LOGIN_URL, protocol, server); //coding sprintf from long ago memory, please ignore
but I really want to stay away from C strings if I can help it.
The stringbuilder() approach requires me to chunk up my constant strings and assemble them when I want to use them. It's a good approach, but what I want to do is neater.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…