outputting items into a format

I have a struct array set to take inputs then output them in a sort of table.

I'm trying to do this using \t but it seems as though if one input is too many characters long, it will push the next entry farther away... which is seen as an issue in the output below


Car			Color			Doors
Honda		        Red			4
BMW			Black			4
Lamborghini		     Yellow			2


 
cout << vehic[i].car << "\t\t" << vehic[i].color << "\t\t" << vehic[i].doors << endl;


is there a better way to format the output of this struct?



If not, then I would take the alternative of only displaying a certain number of characters in the output.
So some how set the string vehic[i].car to not output more than say 9 characters.
So it would turn out like this

Car			Color			Doors
Honda		        Red			4
BMW			Black			4
Lamborghi	        Yellow		  	2


but how, I do not know.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iomanip>

//...

cout
    << std::setw(20) //Creates a "field" or box. The next item streamed will be inside this box
    << vehic[i].car //<--Will be inside that box created above
    << std::setw(20)
    << vehic[i].color
    << std::setw(20)
    << vehic[i].doors
    << '\n'
;
It works perfectly now, thankyou.
Now I just need to limit the input to 20 chars.

I have an if statement after each of my inputs denying more than one word (no space between chars) that directs to a error statement and then resets the users input.
I'm sure there's some other || I can add to it that checks if the input was more than 20 chars?
Assuming you are using strings, you can just check the size() method.
Topic archived. No new replies allowed.