formatting output data neatly C++ -
this question has answer here:
- format output in table, c++ 4 answers
when print results of program screen, data on place want align results best possible. using setw(10) in order it's not working can me?
thanks
this output looks like:
this print function:
void print(const call_record *call_db, int & count) { cout << fixed << showpoint << setprecision(2); for(int i= 0; <= count; i++) { cout << call_db[i].firstname <<" " << call_db[i].lastname <<" " << call_db[i].cell_number <<setw(15) << call_db[i].relays <<setw(10) << call_db[i].call_length; cout <<setw(10) << call_db[i].net_cost <<setw(10) << call_db[i].call_rate << setw(10) << call_db[i].call_tax <<setw(10) << call_db[i].total_cost; cout << endl; } }
you must, of course, set width of output of strings (or of combined name):
cout << std::setw(20) << (call_db[i].firstname + call_db[i].lastname);
(assuming these std::string
s such +
concatenates them).
Comments
Post a Comment