Answer the question
In order to leave comments, you need to log in
An analogue of QStringBuilder for vanilla c++. Where to get?
Where can I get an analogue of QStringBuilder for vanilla c++?
So that you can also beautifully and efficiently concatenate std:: strings without unnecessary memory allocation.
In style
std::string val = "hello world";
int p = 100500;
std::string result = '[' % val % " : " % p % ']';
Answer the question
In order to leave comments, you need to log in
Based on AtomKrieg answer
https://gist.github.com/QW0101/a57e3c59bd7c9c39ff19
std::stringstream
Regarding "extra memory allocation" - it is necessary to take implementations and compare (i.e. I can't say how much QStringBuild is better/worse than std::stringstream), but, as they say, look&feel is almost the same. Replace percentages with << and then call .str()
#include <boost/format.hpp>
#include <iostream>
int main() {
std::string val = "hello world";
boost::format f("[%s : %i]");
int p = 100500;
std::cout << boost::str(f % val % p) << std::endl;
std::cout << boost::str(f % val % (p - 1)) << std::endl; //Can be reused
std::cout << boost::str(boost::format("Hello, %s!") % "@Taraflex") << std::endl; //Can be initialized in place
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question