minister1
جمعه 06 تیر 1393, 17:08 عصر
سلام دوستان و استادان گرامی
من یک برنامه دفترچه تلفن با متغیر اسم و فامیل و شماره نوشتم که میگیره و در فایل هم ذخیره میکنه و وقتی اجرا شد اون فایل رو بخونه . تا یه جاهایی نوشتم
#include <iostream>
#include <string.h>
#include <fstream>
#include <cstdio>
using namespace std;
struct contact{
char name[20];
char family[35];
long int number;
};
int main(){
contact A[100];
ofstream fout("output.txt");
ifstream fin("input.txt");
int i,j,x,k=0,y;
cout<<"\n";
cout<<"\t"<<"\t"<<"\t"<<"\t"<<"Phone BooK\n";
cout<<"\n";
cout<<"Lotfan gozine morede nazar ra entekhab konid : \n"<<"1-ezafe kardane mokhatabe jadid\n"<<"2-hazf kardane mokhatab\n"<<"3-viareyeshe mokhatabin\n";
cout<<"4-jostejoo\n"<<"5-Display All\n"<<"6-Exit\n"<<endl;
cout<<"gozineye entekhabie shoma : \t";
fin>>A[0].name>>A[0].family>>A[0].number;
cin>>x;
switch (x) {
case 1:
cout<<"lotfan tedade mokhatabani ke ghasd darid ezafe konid vared namaeed\n";
cin>>y;
k+=y;
for(i=0;i<y;i++){
cout<<"plz enter fristname\n";
cin>>A[i].name;
cout<<"plz enter lastname\n";
cin>>A[i].family;
cout<<"plz enter telephone number :\n ";
cin>>A[i].number;
cout<<endl;
fout<<A[i].name<<"\t";
fout<<A[i].family<<"\t";
fout<<A[i].number<<"\n";
}
case 2:
cout<<A[0].name<<"\t"<<A[0].family<<"\t"<<A[0].number<<"\n";
cout<<A[1].name<<"\t"<<A[1].family<<"\t"<<A[1].number;
break;
}
system("pause");
return 0;
}
مشکل اینجاست که نمیدونم چجوری بهش بگم همون فایل تکست رو انقدر بگیر تا تموم بشه و باید دستی بهش بگم مثلا A[0] رو بگیر A[1] رو بگیر ... تا آخر.
ممنون میشم راهنمایی کنید
من یک برنامه دفترچه تلفن با متغیر اسم و فامیل و شماره نوشتم که میگیره و در فایل هم ذخیره میکنه و وقتی اجرا شد اون فایل رو بخونه . تا یه جاهایی نوشتم
#include <iostream>
#include <string.h>
#include <fstream>
#include <cstdio>
using namespace std;
struct contact{
char name[20];
char family[35];
long int number;
};
int main(){
contact A[100];
ofstream fout("output.txt");
ifstream fin("input.txt");
int i,j,x,k=0,y;
cout<<"\n";
cout<<"\t"<<"\t"<<"\t"<<"\t"<<"Phone BooK\n";
cout<<"\n";
cout<<"Lotfan gozine morede nazar ra entekhab konid : \n"<<"1-ezafe kardane mokhatabe jadid\n"<<"2-hazf kardane mokhatab\n"<<"3-viareyeshe mokhatabin\n";
cout<<"4-jostejoo\n"<<"5-Display All\n"<<"6-Exit\n"<<endl;
cout<<"gozineye entekhabie shoma : \t";
fin>>A[0].name>>A[0].family>>A[0].number;
cin>>x;
switch (x) {
case 1:
cout<<"lotfan tedade mokhatabani ke ghasd darid ezafe konid vared namaeed\n";
cin>>y;
k+=y;
for(i=0;i<y;i++){
cout<<"plz enter fristname\n";
cin>>A[i].name;
cout<<"plz enter lastname\n";
cin>>A[i].family;
cout<<"plz enter telephone number :\n ";
cin>>A[i].number;
cout<<endl;
fout<<A[i].name<<"\t";
fout<<A[i].family<<"\t";
fout<<A[i].number<<"\n";
}
case 2:
cout<<A[0].name<<"\t"<<A[0].family<<"\t"<<A[0].number<<"\n";
cout<<A[1].name<<"\t"<<A[1].family<<"\t"<<A[1].number;
break;
}
system("pause");
return 0;
}
مشکل اینجاست که نمیدونم چجوری بهش بگم همون فایل تکست رو انقدر بگیر تا تموم بشه و باید دستی بهش بگم مثلا A[0] رو بگیر A[1] رو بگیر ... تا آخر.
ممنون میشم راهنمایی کنید