C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 12th, 2005, 02:27 AM
ekfrancis ekfrancis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 2 ekfrancis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 4 sec
Reputation Power: 0
Question Formatting outputs to the screen

I am programming in C++ and have some knowledge of C, but have never been able to solve my problem by using C. I am printing words to the screen and then printing the number of times that they appear in a document. What I am having problems with is aligning everything. I can get all the words aligned away from the left side by using "\t", but since some words are larger than other, using a tab doesn't align everything. I tried using cout.width() and gave it a number. It still does not align all the numbers. I was wondering if there was a way to do print an aligned column to the screen no knowing the previous size of the word, since the cout command is within a for loop. Thanks.

Reply With Quote
  #2  
Old April 12th, 2005, 04:22 AM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
if you're going to align the text, you're going to have to have at least an idea of what you're upper length is going to be, because there's no way to format previous output to fit the specifications of later output

I'd recommend setting width to the highest value that possibly might occure and set the align to right....

Reply With Quote
  #3  
Old April 12th, 2005, 03:10 PM
ekfrancis ekfrancis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 2 ekfrancis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by B-Con
if you're going to align the text, you're going to have to have at least an idea of what you're upper length is going to be, because there's no way to format previous output to fit the specifications of later output

I'd recommend setting width to the highest value that possibly might occure and set the align to right....



I actually came up with something this afternoon that worked for this example:


PHP Code:
 int length strlen(word); 
cout << word;
cout.width(35-length);
cout << frequency << endl



this will then space everything evenly. Thanks for the help though.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Formatting outputs to the screen


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway