How can i create a boost::format type formatter object using the character-string or std::string.
Trying to use following code which doesn’t run. Want to achieve code equivalent to following code (semantically):
format fobj("first-> %1% , second-> %2%");
std::stringstream s;
s<<fobj %1 %"%1%."; //so that I can use s.str() to create a boost object
// How to create fmt object HERE
ss<< fmt %"replacedtext";
cout<<s.str()<<endl;
cout<<ss.str();
Sample case:
s should be “first-> 1 , second-> %1%.”
so that I can use this s.str() string to create another format object fmt to which i can feed the substitution values.
Any thoughts folks??
It’s not clear to me what you are trying to do, the boost::format docs are a good place to start, there are a number of clear examples showing how to use the class.
You can create a formatter object and feed elements in via different operations (unlike say, printf where all params need to satisfy the
va_argyou pass in).You can then obtain a string from the result.
Be aware there are a number of exceptions that can be thrown.
If you are looking for something that dynamically creates a format string you can do that in any number of ways.