c++ - Unable to create multiple data files -


i trying create multiple file purpose , store different set of data them. code does't seems work. there trouble. not able enter teacher name in output window.please me correct code. here function using this.

#include<iostream> #include<fstream> using namespace std; struct teacher{ int id; char name[50]; char subject[50]; char qualification[50]; char experience[50]; }; teacher teacher; void addition(int a) { char ans='y';         {     teacher.id=a;         fstream sfile;     sfile.open("id.dat",ios::app|ios::out|ios::binary);      cout<<"\n enter teacher name"<<endl;     gets(teacher.name);     cout<<"enter subject taught teacher"<<endl;     gets(teacher.subject);      cout<<"enter qualification "<<endl;     gets(teacher.qualification);     cout<<"enter experience"<<endl;     gets(teacher.experience);     sfile.write((char*)&teacher,sizeof(teacher));     cout<<"continue... (y/n)";     cin>>ans;     sfile.close();      }     while(ans=='y'); } int main(void) { int a,t_id; cout<<"1:new teacher registration , time table creation"<<endl; cout<<"2:modify earlier data"<<endl; cin>>a; char ans='y'; if (a==1) {     cout<<"enter teacher id";     cin>>t_id;     addition(t_id); } //please neglect case 2.  } 

help me code or please suggest other better method this. want generate multiple number of files every time call function.

ios::ate mode used read file.

change code bellow:

sfile.open("t_id.dat",ios::ate); // should change open mode, then. follows sfile.open("t_id.dat",ios::app|ios::out|ios::binary) 

it works.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -