我创建了一类医生,并且我想在记事本文件(Doctor.txt)中插入医生的数据,但是数据没有对称性,因为该行中的输入没有固定长度...
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();
我如何使用固定的输入列宽度生成对称的.txt文件
最佳答案
您可能正在寻找<iomanip>
头文件提供的setw宽度操纵函数,并在此之前或之后使用它,但是您想将每个条目写入该文件。