I am looking for a way to output the elements of a structure I have defined in a Yahtzee program I'm trying to make.
My structure is:
struct card_cell
{
std::string name;
int points;
int state;
}
I want to print it in the format:
name1 name2 name3...
points1 points2 points3...
state1 state2 state3...
across the screen like so.
The different types of structures are stored in a std::vector<card_cell>
, so I can do this by just iterating through the members of the vector and outputting the names, then points, then states in turn.
However, I have enough card_cell
s in the vector that when I print it all this way, the entries begin making new lines by themselves, and mucking up the formatting:
name1 name2 name3...
nameN...
points1 points2 points3...
pointsN...
state1 state2 state3...
stateN...
I want to be able to declare something like const int CELLS_PER_LINE = 6;
and when my iteration prints that number of name
's, it will halt, start a new line and print the next 6 points
values. When it finally reaches the end of the state
s, it will form a new line and start printing the next set of name
s where it left off.
I could brute force and hard-code this, yes, but I was wondering if anyone had an idea of how to do this in a cuter way?
Thanks!