By default, output is right-justified in its field. You can left-justify text output using the
manipulator setiosflags(ios::left). (For now, don’t worry about what this new notation means.) Use
this manipulator, along with setw(), to help generate the following output:
Last name First name Street address Town State
-----------------------------------------------------------
Jones Bernard 109 Pine Lane Littletown MI
O’Brian Coleen 42 E. 99th Ave. Bigcity NY
Wong Harry 121-A Alabama St. Lakeville IL
1
Expert's answer
2013-03-15T09:55:39-0400
#include < iostream > # include <string> # include<iomanip> using namespace std;
void main() {
string name[10], sur[10]; double mon[10]; int i=0; cout<<"Enter names down here: "; while(true){ cout<<"Enter name: "; cin.ignore(); getline (cin,name[i],' '); if (name[i]=="") break; cout<<"Enter surname: "; cin.ignore(); getline (cin,sur[i],' '); cout<<"Enter amount of money: "; cin>>mon[i]; i++; } for (int j=0;j<i;j++){ cout<<setiosflags(ios::left)<<setw(3)<<name[j]<<setw(3)<<" "<<sur[j]<<setw(3)<<" "<<mon[j]<<endl; }
Comments
Leave a comment