I/O Manipulation

Is there a way to manipulate the output on the console screen so that a horizontal list is aligned neatly? For example:
My output currently:
XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX
____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX

I need it to look like this:
XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX
XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX____XXXXXXXX
1
2
#include <iomanip>
using namespace std;


And all of it's mainpultion
http://www.cplusplus.com/reference/iostream/manipulators/

For example, a string array with string lengths no greater than 10:
1
2
3
4
5
for (int i = 0; i < SizeofArray; i++)
{
  if (i % 4 = 0) cout << endl;
  cout << setw(11) << left << stringArray[i];
}
For rough alignments, sticking a few TABs is handy. To do so, use the '\t' character.

Otherwise, iomanip is your friend (specifically, the setw function).

Make sure that you add '\n' or std::endl as appropriate to ensure that none of your data spills onto the next line.
I am somewhat familiar with iomanip...we have used setw, setfill, setprecision, and a few others. I had not seen one yet that can do what I was explaining above, or I haven't manipulated enough times to really grasp what the tools can do...if you are saying that can work, i will mess around with it a bit more. Thanks for your help! I'll let you know if i have any other questions!
Hmmm, i guess a clearer way of saying what I am trying to accomplish is:
I have a file that has x number of lines of data. I want to display that data on the console horizontally, with 5 customerIDs on each horizontal line. So i need some sort of loop that will print the first 5 on one line, then the next 5 on the second line, so on and so forth...
Something like this then?
1
2
3
4
5
6
7
8
9
10
11
12
int data[100000]; // data buffer;

for (int i = 0, lines = 0; i < 100000; ++i)
{
    std::cout << std::setw(11) << data[i];

    if (++lines < 5)
    {
        lines = 0;
        std::cout << std::endl;
    }
}
Well, that puts all customer codes on a separate line.
I need 5 customer codes per line...
Figured it out. Your code was right, I just needed to say
 
if (++lines > 5)

instead of less than. That puts it exactly how i need it
Thank you for the spark!!!
Topic archived. No new replies allowed.