I am trying to parse through a text file and have it output the contents onto the console with formatting by using setw(). My problem is that only the first row is formatted correctly, with the rest defaulting back to the left.
while (test)
{
cout << setw(20) << right;
string menu;
price = 0;
getline(test, menu, ',');
test >> price;
cout << setw(20) << right << menu;;
if (price)
cout << right << setw(10) << price;
}
My goal is to get the output to align to the longest word (which is 20 spaces in length) on the right, but my output is ending up like this:
WordThatAlignsRight
notAligning
my longest sentence goal align
notAligning
I am wanting each sentence to right align 20 spaces throughout the loop. Any help is appreciated, thanks!