Examples

Top  Previous  Next

Scripts > Class elements and c++ instructions > Formatting instructions > Examples

 

Simple output, with reordering:

 

out << format("%1% %2% %3% %2% %1% \n") % "11" % "22" % "333";

 

It prints : "11 22 333 22 11 \n"

 

 

Simple output, no reordering:

 

out << format("writing %||,  x=%|| : %||-th step \n") % "toto" % 40.23 % 50;

 

It prints : "writing toto, x=40.23 : 50-th step \n"

 

 

More precise formatting, with positional directives:

 

out << format("(x,y) = (%|1$+5|,%|2$+5|) \n") % -23 % 35;   

 

It prints : "(x,y) = ( -23, +35) \n"

 

 

Two ways to express the same thing:

 

out << format("(x,y) = (%|+5|,%|+5|) \n") % -23 % 35;

out << format("(x,y) = (%|1$+5|,%|2$+5|) \n") % -23 % 35;

 

all those print : "(x,y) = ( -23, +35) \n"

 

 

New formatting feature: 'absolute tabulations', useful inside loops, to insure a field is printed at the same position from one line to the next, even if the widthes of the previous arguments can vary a lot.

 

for(unsigned int i=0; i < names.size(); ++i)

   out << format("%|1$|, %|2$|, %|40t|%|3$|\n") % names[i] % surname[i] % tel[i];

 

For some std::vector names, surnames, and tel (see sample_new_features.cpp) it prints:

 

Marc-François Michel, Durand,           +33 (0) 123 456 789

Jean, de Lattre de Tassigny,            +33 (0) 987 654 321

 

 



This page belongs to the TextTransformer Documentation

Home  Content  German