Home » U++ Library support » U++ Core » Format Issues - Dynamic width and alignment
Format Issues - Dynamic width and alignment [message #18866] |
Wed, 29 October 2008 17:48  |
captainc
Messages: 278 Registered: December 2006 Location: New Jersey, USA
|
Experienced Member |
|
|
Hey, I'm trying to use alignment and dynamic widths based on the size of strings with the Format function.
Ex:
Cout() << Format("|%20=s|\n", "test"); // Works as expected
Cout() << Format("|%*=s|\n", 20, "test"); // Seg Fault Heap Corrupted
How can I use * to insert the width I want dynamically?
Update:
Found a small workaround...
String fm("");
int width = 20;
fm.Cat() << "%" << width << "=s";
Cout() << Format(fm, "test");
Would still like to know if it is possible with just 1 formatting line though.
[Updated on: Wed, 29 October 2008 18:05] Report message to a moderator
|
|
|
Re: Format Issues - Dynamic width and alignment [message #18893 is a reply to message #18866] |
Thu, 30 October 2008 23:29   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
captainc wrote on Wed, 29 October 2008 12:48 | Hey, I'm trying to use alignment and dynamic widths based on the size of strings with the Format function.
Ex:
Cout() << Format("|%20=s|\n", "test"); // Works as expected
Cout() << Format("|%*=s|\n", 20, "test"); // Seg Fault Heap Corrupted
How can I use * to insert the width I want dynamically?
Update:
Found a small workaround...
String fm("");
int width = 20;
fm.Cat() << "%" << width << "=s";
Cout() << Format(fm, "test");
Would still like to know if it is possible with just 1 formatting line though.
|
Obviously, something like
Cout() << Format(String().Cat() << '%' << width << "=s", "test")
would work. Anyway, the original code should work as well, something to fix (working on it).
BTW, you do not need .Cat there:
fm << "%" << width << "=s";
that is only needed for 'String().Cat()' construct - you cannot write
String() << "hello"
in standard C++.
Mirek
|
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 20:39:49 CEST 2025
Total time taken to generate the page: 0.03568 seconds
|