formatting output data neatly C++ -


this question has answer here:

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:

enter image description here

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::strings such + concatenates them).


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -