Anwar Ali
Anwar Ali

Reputation: 31

fix the column width in .txt file using c++

i have created one class of doctor and i want to insert data of doctor in note pad file (Doctor.txt) but data do not have a symmetry because there is no fixed length of my inputs in the line...

        int DocID;
        string Name,Department,Specification,Address,PhNo ;
        Doctor D;
        ofstream myfile;
        myfile.open ("Doctor.txt",ios::app);
          cout<<"please enter doctor ID: ";
          cin>> DocID;
          cout<<"please enter doctor Name: ";
          cin>> Name;
          cout<<"please enter doctor Department name: ";
          cin>> Department;
          cout<<"please enter doctor specification: ";
          cin>> Specification;
          cout<<"please enter doctor Address: ";
          cin>> Address;
          cout<<"please enter doctor Phone Number: ";
          cin>> PhNo;

          D.set_data(DocID,Name,Department,Specification,Address,PhNo);
          myfile <<endl<<D.get_DocID()<<"  "<<D.get_Name()<<" "<<D.get_Department()<<" "<<D.get_Specification()<<" "<<D.get_Address()<<" "<<D.get_PhNo();
          myfile.close();

how can i generate a symmetrical .txt file using fixed width of columns of inputs

Upvotes: 3

Views: 1895

Answers (1)

cpx
cpx

Reputation: 17577

You might be looking for setw width manipulator function provided by <iomanip> header file and using it before or after or however you want to write each entry to the file.

Upvotes: 1

Related Questions