I am trying to line everything up. Problem is it counts how many characters the name is and setw how far past that name. So all the names are different lengths. I cant get everythnig to line up.. I have tried <<left and << right and << setw
what i need the putput to look like is this:
Code:
name location acres rating
---- -------- ----- ------
Cooper Mountain Willamette Valley 100 47
Del Rio Bear Creek Valley 200 37
Duck Pond Cellars Willamette Valley 845 70
Gallo Napa Valley 200 25
LongSword Applegate Valley 16 85
Lopez Island Vinyard San Juan Islands 7 95
Weisinger's of Ashland Bear Creek Valley 6 83
Code:
void list::displayByName(ostream& out) const
{
winery *wineryPtr;
wineryPtr->displayHeadings(out);
node *curr = headByName;
while ( curr )
{
out << curr->item.getName() << setw(25)
<< curr->item.getLocation() << setw(15)
<< curr->item.getAcres() << setw(15)
<< curr->item.getRating()
<< endl;
curr = curr->nextByName;
}
}
problem is what i am getting is:
Code:
CS260 - Lab1 - Corey Mattis
+++ list by name
Name Location Rating Acre
----- ------------------
Cooper Mountain Willamette Valley 100 47
Del Rio Bear Creek Valley 200 37
Duck Pond Cellars Willamette Valley 845 70
Gallo Napa Valley 200 25
LongSword Applegate Valley 16 85
Lopez Island Vinyard San Juan Islands 7 95
Weisinger's of Ashland Bear Creek Valley 6 83
I did have some success with getting the lengths of the name s and using that in setw
However, it didnt line up like i wanted.
Code:
string name = curr->item.getName();
size_t fieldWidth = name.size();
out << curr->item.getName() << setw(-fieldWidth + 45)