Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
captainc is currently offline  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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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
Re: Format Issues - Dynamic width and alignment [message #18901 is a reply to message #18893] Fri, 31 October 2008 10:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Fixed.

Mirek
Re: Format Issues - Dynamic width and alignment [message #18925 is a reply to message #18901] Fri, 31 October 2008 23:47 Go to previous message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Very awesome indeed! Thank you for the quick fix.
Previous Topic: Compile error in Stream.cpp with GCC (Ubuntu 8.10)
Next Topic: Report serialization
Goto Forum:
  


Current Time: Fri Mar 29 00:57:04 CET 2024

Total time taken to generate the page: 0.01685 seconds