![]() |
|
#1
|
|||
|
|||
How to make columns when reading in files???Hey how would i make columns when im reading in a text document? My prorgam outputs everything correctly, but my numbers dont line up when my program runs b/c all my "players" names are different sizes...
here is my code: CPP / C++ / C Code:
output looks something like this: D.Jeter 623 A.Rodriguez 572 J.Damon 593 J.Posada 465 J.Giambi 446 B.Williams 420 M.Cabrera 460 R.Cano 482 A.Pillips 246 M.Cairo 222 B.Crosby 87 B.Abreu 209 H.Matsui 172 ..not exactly like that, but you get the idea....any help would be great, thanks. |
|
#2
|
|||
|
|||
Re: How to make columns when reading in files???Quote:
I think you mean when you are writing the document, right? Well, I usually set up titles and column headers visually. Just diddle around with a text editor until it looks right and then put the literal strings in output statements. To line up names, I would probably left-justify them, and numbers are usually right-justified. CPP / C++ / C Code:
Output for a couple of names: Code:
Of course you will adjust the widths to accommodate longest possible names and make it "look good" to you --- or your boss or teacher or whoever the heck is the target market (audience) for this product. By putting each thing on its own line, it's easier (for me, anyhow) to keep track of what changes will affect which items. Notes: 1. You should always test to see that files are opened properly and probably print some kind of message to indicate problems. 2. You should always test results of read operations to make sure the input stream is still OK. Note that the way you had set up your loop it reads the last line twice (since the eof flag isn't set until after you have tried to read past the end of the file). The value of the expression in the while(...) statement is a boolean that is false if input stream has failed (including the case where the program has tried to read past the end of the file), and the value is true if it's OK so far. Regards, Dave Last edited by davekw7x : 02-May-2007 at 15:00.
|
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bloodshed Dev C++ Project Options | JdS | CPP / C++ Forum | 6 | 11-Nov-2005 17:23 |
| Need help reading data from files | blitzy | C Programming Language | 5 | 15-Mar-2005 19:07 |
| GIMcontacts - a gim fltk fluid venture | cable_guy_67 | FLTK Forum | 0 | 14-Feb-2005 14:18 |
| Reading and writing binary files in certain format | Dream86 | CPP / C++ Forum | 10 | 06-Aug-2004 10:38 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The