I need to output multiple variables in a line that has a set width but the variables are different sizes and I output different numbers on each line. Thus I have, say setw(30), between every single variable.
Here is my current code:
1 2 3 4 5 6 7 8 9 10 11
if (*kwIterator == *j)
{
cout << setw(30);
for (list<string>::iterator k = mListIt->begin(); k != j; ++k)
cout << *k << " ";
cout << "|";
cout << setw(30);
for (list<string>::iterator l = j; l != mListIt->end(); ++l)
cout << *l << " ";
cout << endl;
}
Right now I get huge gaps (like this):
KWIC
Key Word in Context List
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| A View To A Kill
A View To | A Kill
Live | And Let Die
Die | Another Day
Diamonds | Are Forever
| Casino Royale
Die Another | Day
The Living | Daylights
| Diamonds Are Forever
| Die Another Day
Live And Let | Die
Tomorrow Never | Dies
| Dr. No
The World Is Not | Enough
For Your | Eyes Only
| For Your Eyes Only
Diamonds Are | Forever
| From Russia With Love
The Man With The | Golden Gun
| GoldenEye
| Goldfinger
The Man With The Golden | G
un
On | Her Majesty's Secret
Service
The World | Is Not Enough
A View To A | Kill
License To | Kill
Live And | Let Die
| License To Kill
You Only | Live Twice
| Live And Let Die
The | Living Daylights
From Russia With | Love
The Spy Who | Loved Me
On Her | Majesty's Secret Servic
e
The | Man With The Golden G
un
The Spy Who Loved | Me
| MoonRaker
Tomorrow | Never Dies
Dr. | No
The World Is | Not Enough
| Octopussy
Quantum | Of Solace
| On Her Majesty's Secre
t Service
You | Only Live Twice
For Your Eyes | Only
| Quantum Of Solace
Casino | Royale
From | Russia With Love
On Her Majesty's | Secret Ser
vice
On Her Majesty's Secret | Serv
ice
Quantum Of | Solace
The | Spy Who Loved Me
| The Man With The Golden
Gun
The Man With | The Golden G
un
| The Living Daylights
| The World Is Not Enough
| The Spy Who Loved Me
| Thunderball
A View | To A Kill
License | To Kill
| Tomorrow Never Dies
You Only Live | Twice
A | View To A Kill
The Spy | Who Loved Me
The Man | With The Golden Gu
n
From Russia | With Love
The | World Is Not Enough
| You Only Live Twice
For | Your Eyes Only
Press any key to continue . . .
I can't think of how else to use setw to get 30 spaces on each side of the "|" symbol. My goal output is:
KWIC
Key Word in Context List
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|A View To A Kill
A View To |A Kill
|A View To A Kill
A View To |A Kill
Live |And Let Die
Die |Another Day
Diamonds |Are Forever
|Casino Royale
Die Another |Day
The Living |Daylights
|Diamonds Are Forever
|Die Another Day
Live And Let |Die
|Die Another Day
Live And Let |Die
Tomorrow Never |Dies
|Dr. No
The World Is Not |Enough
For Your |Eyes Only
for (kwIterator = stringset.begin(); kwIterator != stringset.end(); ++kwIterator)
{
for (mListIt = masterList.begin(); mListIt != masterList.end(); mListIt++)
for (list<string>::iterator j = mListIt->begin(); j != mListIt->end(); ++j)
if (*kwIterator == *j)
{
string leftColumn;
for (list<string>::iterator k = mListIt->begin(); k != j; ++k)
{
leftColumn += *k;
leftColumn += " ";
}
cout << setw(30) << leftColumn;
cout << "| ";
for (list<string>::iterator l = j; l != mListIt->end(); ++l)
{
cout << *l << " ";
}
cout << endl;
}
}
Now my output is:
KWIC
Key Word in Context List
<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| A View To A Kill
A View To | A Kill
Live | And Let Die
Die | Another Day
Diamonds | Are Forever
| Casino Royale
Die Another | Day
The Living | Daylights
| Diamonds Are Forever
| Die Another Day
Live And Let | Die
Tomorrow Never | Dies
| Dr. No
The World Is Not | Enough
For Your | Eyes Only
| For Your Eyes Only
Diamonds Are | Forever
| From Russia With Love
The Man With The | Golden Gun
| GoldenEye
| Goldfinger
The Man With The Golden | Gun
On | Her Majesty's Secret Service
The World | Is Not Enough
A View To A | Kill
License To | Kill
Live And | Let Die
| License To Kill
You Only | Live Twice
| Live And Let Die
The | Living Daylights
From Russia With | Love
The Spy Who | Loved Me
On Her | Majesty's Secret Service
The | Man With The Golden Gun
The Spy Who Loved | Me
| MoonRaker
Tomorrow | Never Dies
Dr. | No
The World Is | Not Enough
| Octopussy
Quantum | Of Solace
| On Her Majesty's Secret Service
You | Only Live Twice
For Your Eyes | Only
| Quantum Of Solace
Casino | Royale
From | Russia With Love
On Her Majesty's | Secret Service
On Her Majesty's Secret | Service
Quantum Of | Solace
The | Spy Who Loved Me
| The Man With The Golden Gun
The Man With | The Golden Gun
| The Living Daylights
| The World Is Not Enough
| The Spy Who Loved Me
| Thunderball
A View | To A Kill
License | To Kill
| Tomorrow Never Dies
You Only Live | Twice
A | View To A Kill
The Spy | Who Loved Me
The Man | With The Golden Gun
From Russia | With Love
The | World Is Not Enough
| You Only Live Twice
For | Your Eyes Only
Press any key to continue . . .