just another thought... in coldfusion code this would be one way... however coldfusion isn't strictly typed, so it's pretty easy here....
function formatOutput(spaces, outputString){
var remainingSpaces = arguments.spaces - (len(arguments.outputStrin
var i = 0;
writeoutput(" "); //leading space
writeoutput(outputString);
for(i = 1; i lte remainingSpaces; i=i+1){ //loop over remaining spaces, could also use repeatString() but this proves the concept better
writeoutput(" "); //write the remaining spaces to maintain column spacing...
}
writeoutput("\n"); //newline
}
so the result of formatOutput(10, "sometn") is " _ sometn _ _ _ "
the "_" would be the spaces applied...
seeing how I could do it in C++
thanks!
Main Topics
Browse All Topics





by: jkrPosted on 2007-07-01 at 10:15:50ID: 19399587
'cout' can handle that if you pass the appropriate I/O manipulators, e.g.
#include <iostream>
#include <iomanip>
using namespace std;
//...
cout << setwidth(10) << setfill(' ') << num;