GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Nov-2008, 10:57
Vicki Vicki is offline
New Member
 
Join Date: Feb 2008
Posts: 6
Vicki is on a distinguished road

Output into Columns


I'm trying to output the results of a program I've written into a table-like format. At the moment Im using the setw(x) function to print a series of numbers to columns but they are not lining up because a space is narrower than a digit. I'm wondering if anyone knows of a way around this to try neaten things up?

Any help would be greatly appreciated.

Here's the relevent code:

CPP / C++ / C Code:

out << " Distance from Start of Element:\t";
out << setw(w) << (StructureMembers[i].getL()*0);
out << setw(w) << StructureMembers[i].getL()/4;
out << setw(w) << StructureMembers[i].getL()/2;
out << setw(w) << 3*StructureMembers[i].getL()/4;
out << setw(w) << StructureMembers[i].getL() << endl<< endl;

out << " Transverse Deflection:\t\t";
out.precision(3);
out << setw(w) << Net_X.getElement(1, 1);
out << setw(w) << Net_X.getElement(1, 26);
out << setw(w) << Net_X.getElement(1, 51);
out << setw(w) << Net_X.getElement(1, 76);
out << setw(w) << Net_X.getElement(1, 101) << "\t(m)" << endl << endl;


It probably makes little sense out of context. To try clear this up StructureMembers[i].getL() returns the length of a steel bar
Net_X.getElement(i, j) returns a value in either decimal form or scientific notation.

The corresponding output to this is:

Distance from Start of Element: 0.000 0.625 1.25 1.88 2.50
Transverse Deflection: -2.14e+005 -2.14e+005 -2.14e+005 -2.14e+005 -2.14e+005 (m)

Unfortionatly you can't see how this doesn't line up but you can understand the range of numbers I have.
  #2  
Old 12-Nov-2008, 11:08
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Output into Columns


Quote:
Originally Posted by Vicki
It probably makes little sense out of context.
Correct. You should recognize that we can only work on the information provided. It is your responsibility to articulate the situation clearly.
Quote:
...a space is narrower than a digit.
Huh? If you are displaying the results on a monitor, the width of a space & digit are identical.
Quote:
Unfortionatly you can't see how this doesn't line up but you can understand the range of numbers I have.
Increasing the value of w (the field's width) doesn't resolve the problem?
  #3  
Old 12-Nov-2008, 11:18
Vicki Vicki is offline
New Member
 
Join Date: Feb 2008
Posts: 6
Vicki is on a distinguished road

Re: Output into Columns


I'm attaching a screenshot of the output which is a .txt file. Hope this is clearer....
Attached Images
File Type: jpg ScreenHunter_01 Nov. 12 17.12.jpg (87.2 KB, 15 views)
  #4  
Old 12-Nov-2008, 13:01
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Output into Columns


Quote:
Originally Posted by Vicki
I'm attaching a screenshot...
Again, increasing the value of w (the field's width) doesn't resolve the problem?
  #5  
Old 12-Nov-2008, 14:19
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: Output into Columns


The issue is whatever program you're opening the .txt file in is not using monospace font. If you looked at the output on the console, it most likely would line up. Pick a monospace font, it'll probably look like what you want.
  #6  
Old 13-Nov-2008, 04:31
Vicki Vicki is offline
New Member
 
Join Date: Feb 2008
Posts: 6
Vicki is on a distinguished road

Re: Output into Columns


Quote:
Originally Posted by dlp
The issue is whatever program you're opening the .txt file in is not using monospace font. If you looked at the output on the console, it most likely would line up. Pick a monospace font, it'll probably look like what you want.

Using the montype text fixes the problem, thanks.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 65 19-Aug-2009 08:50
Bit stuffing agnostos C Programming Language 17 12-Sep-2006 21:10
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 15:46
Formatting output into columns Extro C Programming Language 5 24-Jun-2005 14:30
No output from loop function crystalattice C++ Forum 2 20-Dec-2004 21:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:43.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.