PDA

View Full Version : سورس ویرایش و حذف در فایل



25farshid
شنبه 11 دی 1389, 19:45 عصر
سلام کسی سورس ویرایش و حذف در فایل رو داره برام بزاره.یا یه راهنمایی .با تشکر.

Pouri_sb
دوشنبه 13 دی 1389, 23:25 عصر
اولین پروژمه :ی خیلی بد کد زدم اما ازش می تونی کار با فایل رو یاد بگیری



#include "stdafx.h"
#include "iostream.h"
#include "conio.h"
#include "fstream.h"
#include "string.h"
#define m 50
struct date{
int day;
int month;
int year;
}b_date;
struct student{
char f_name[51];
char l_name[51];
char father[51];
char id1[11];//shomare daneshjoE
char id2[11];//shomare shenaqsname
struct date b_date;
char POB[51];//MAHALE TAVALOD
float avg;
char emission[51];//mahale sodoor shenasname
char add[501];
}st[m];
void creat(int);
int insert(int,int);
void Delete(int);
void update(int);
void search(int);
void main(int argc, char* argv[])
{
cout<<"if you want to get a good result,don't use backspace!please\nand Be careful,'a' and 'A' are different";
int n;
cout<<"\nenter the number of student(after your last change of information"<<endl;
cin>>n;
creat(n);
int t=0;
t=insert(n,t);
n+=t;
update(n);
search(n);
Delete(n);
}
void creat(int n)
{
char ans;
cout<<"Is it your first time that you are entering the students' enformation?(y or n)\t";
cin>>ans;
if(ans=='y')
{
for(int i=0;i<n;i++)
{
cout<<"enter these informotion for student "<<i+1<<" :\n";
cin.get();
cout<<"name: ";
cin.get(st[i].f_name,50);
cin.get();
cout<<"\nfamily: ";
cin.get(st[i].l_name,50);
cin.get();
cout<<"\nfather's name: ";
cin.get(st[i].father,50);
cin.get();
cout<<"\nshomare daneshjooE: ";
cin>>st[i].id1;
cout<<"\nshomare shenasname: ";
cin>>st[i].id2;
cout<<"\nthe day/month/year of birthday(seprate with enter)"<<endl;
cin>>st[i].b_date.day>>st[i].b_date.month>>st[i].b_date.year;
cin.get();
cout<<"\nmahale tavalod: ";
cin.get(st[i].POB,50);
cin.get();
cout<<"\navrage: ";
cin>>st[i].avg;
cin.get();
cout<<"\nmahale sodoore shenasname: ";
cin.get(st[i].emission,50);
cin.get();
cout<<"\naddres(don't seprate with enter)\n";
cin.get(st[i].add,500);
}
ofstream p1("F:\\students.txt");
for(i=0;i<n;i++)
p1<<st[i].f_name<<"\t"<<st[i].l_name<<"\t"<<st[i].father<<"\t"<<st[i].id1<<"\t"<<st[i].id2<<"\t"<<st[i].b_date.day<<"\t"<<st[i].b_date.month<<"\t"<<st[i].b_date.year<<"\t"<<st[i].POB<<"\t"<<st[i].avg<<"\t"<<st[i].emission<<"\t"<<st[i].add<<"\t"<<endl;
p1.close();
}
else
{
ifstream p1("F:\\students.txt");
for(int i=0;i<n;i++)
p1>>st[i].f_name>>st[i].l_name>>st[i].father>>st[i].id1>>st[i].id2>>st[i].b_date.day>>st[i].b_date.month>>st[i].b_date.year>>st[i].POB>>st[i].avg>>st[i].emission>>st[i].add;
p1.close();
cout<<"\nThis is your list\n";
for(i=0;i<n;i++)
{
cout<<(i+1)<<"."<<st[i].f_name<<"\t"<<st[i].l_name<<"\t"<<st[i].father<<"\t"<<st[i].id1<<"\t"<<st[i].id2<<"\t"<<st[i].b_date.day<<"/"<<st[i].b_date.month<<"/"<<st[i].b_date.year<<"\t"<<st[i].POB<<"\t"<<st[i].avg<<"\t"<<st[i].emission<<"\t"<<st[i].add<<endl;
}
}
}
int insert(int n,int t)
{
char ans='y';
while(ans=='y')
{
cout<<"\ndo you want to add anather student(y or n)\n";
cin>>ans;
if(ans=='y')
{
cout<<"enter these information:\n";
cin.get();
cout<<"name: ";
cin.get(st[n+t].f_name,50);
cin.get();
cout<<"\nfamily: ";
cin.get(st[n+t].l_name,50);
cin.get();
cout<<"\nfather's name: ";
cin.get(st[n+t].father,50);
cin.get();
cout<<"\nshomare daneshjooE: ";
cin>>st[n+t].id1;
cout<<"\nshomare shenasname: ";
cin>>st[n+t].id2;
cout<<"\nthe day/month/year of birthday(seprate with enter)"<<endl;
cin>>st[n+t].b_date.day>>st[n+t].b_date.month>>st[n+t].b_date.year;
cin.get();
cout<<"\nmahale tavalod: ";
cin.get(st[n+t].POB,50);
cin.get();
cout<<"\navrage: ";
cin>>st[n+t].avg;
cin.get();
cout<<"\nmahale sodoore shenasname: ";
cin.get(st[n+t].emission,50);
cin.get();
cout<<"\naddres(don't seprate with enter)\n";
cin.get(st[n+t].add,500);
fstream p1("F:\\students.txt",ios::app);
p1<<st[n+t].f_name<<"\t"<<st[n+t].l_name<<"\t"<<st[n+t].father<<"\t"<<st[n+t].id1<<"\t"<<st[n+t].id2<<"\t"<<st[n+t].b_date.day<<"\t"<<st[n+t].b_date.month<<"\t"<<st[n+t].b_date.year<<"\t"<<st[n+t].POB<<"\t"<<st[n+t].avg<<"\t"<<st[n+t].emission<<"\t"<<st[n+t].add<<"\t"<<endl;
p1.close();
t++;
}
else
return(t);
}
}

V0RTEX
چهارشنبه 15 دی 1389, 17:09 عصر
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("Filename");
int main()
{
int x;
fin >> x;
ofstream fout("Filename");
fout << x*x;
fin.close():
fout.clsoe();
}
با این هم یک کارهایی میتونی بکنی:دی

25farshid
پنج شنبه 16 دی 1389, 15:45 عصر
مشه لطف کنی یه کمی در مورد سورس ویرایش توضیح بدی.با تشکر.