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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With