1 / 18

Save and Retrieve Data Using C++ File Streams

This article provides a complete guide on how to save and retrieve data using file streams in C++. It covers the essential libraries, primarily `<iostream.h>` and `<fstream.h>`, and demonstrates various methods for writing to and reading from files. The examples include creating files, appending data, reading data into character arrays, and searching for specific entries. With practical code snippets, you'll learn to manage file I/O operations effectively in your applications. Ideal for beginners and intermediate programmers looking to enhance their skills.

amy-weeks
Télécharger la présentation

Save and Retrieve Data Using C++ File Streams

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. / ذخيره و بازيابي

  2. 5ذخیره بازیابی در C++

  3. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() } fstream f1; f1.open("d:\\aaa.txt",ios::out); f1<<"Ali Reza”; {

  4. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; f1.open("d:\\aaa.txt",ios::app); f1<<"Ali Reza"<<endl; }

  5. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; f1.open("d:\\aaa.txt",ios::out); f1<<"Ali Reza"<<endl; f1<<"Hamid"; }

  6. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a; f1.open("d:\\aaa.txt",ios::in); f1>>a; cout<<a; }

  7. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a[5]; f1.open("d:\\aaa.txt",ios::in); f1>>a; cout<<a; }

  8. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a; f1.open("d:\\aaa.txt",ios::in); f1>>a; cout<<a; f1>>a; cout<<a; f1>>a; cout<<a; f1>>a; cout<<a; f1>>a; cout<<a; }

  9. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a; f1.open("d:\\aaa.txt",ios::in); f1.unsetf(ios::skipws); f1>>a; cout<<a; f1>>a; cout<<a; f1>>a; cout<<a; f1>>a; cout<<a; f1>>a; cout<<a; }

  10. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a; f1.open("d:\\aaa.txt",ios::in); f1.unsetf(ios::skipws); for(int c=0;c<=20;c++) { f1>>a; cout<<a; } }

  11. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a; f1.open("d:\\aaa.txt",ios::in); f1.unsetf(ios::skipws); for(int c=0;c<=20;c++) { f1>>a; cout<<a; cout<<f1.eof(); } }

  12. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a; f1.open("d:\\aaa.txt",ios::in); f1.unsetf(ios::skipws); while(!f1.eof()) { f1>>a; cout<<a; } }

  13. ذخیره و بازیابی در C++ main() { fstream f1,f2; char a,b; f1.open("d:\\aaa.txt",ios::in); f2.open("d:\\bbb.txt",ios::out); f1.unsetf(ios::skipws); while(!f1.eof()) { f1>>a; if(f1.eof()) b=' '; else f1>>b; f2<<b<<a; } f1.close(); f2.close(); }

  14. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char a[20]; cin>>a; f1.open("d:\\aaa.txt",ios::app); f1<<a<<endl; }

  15. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; char Name[20]; char Fam[30]; char Tell[20]; cout<<"Enter Name = ";cin>>Name; cout<<"Enter Fam = ";cin>>Fam; cout<<"Enter Tell = ";cin>>Tell; f1.open("d:\\aaa.txt",ios::app); f1<< Name<<" "<<Fam<<" "<<Tell <<endl; cout<<"Saved"<<endl; }

  16. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> main() { fstream f1; int n; char Name[20]; char Fam[30]; char Tell[20]; cout<<" Name "<<'\t'<<" Fam "<<'\t'<<" Tell "<<endl; cout<<"-------"<<'\t'<<"-------"<<'\t'<<"-------"<<endl; f1.open("d:\\aaa.txt",ios::in); while(!f1.eof()) { f1>>Name>>Fam>>Tell; cout<<Name<<'\t'<<Fam<<'\t'<<Tell<<endl; } }

  17. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> #include<string.h> main() { fstream f1; char Name[20]; char Fam[30]; char Tell[20]; char SearchFam[30]; cout<<"Enter fam for search = "; cin>>SearchFam; cout<<endl; cout<<" Name "<<'\t'<<" Fam "<<'\t'<<" Tell "<<endl; cout<<"-------"<<'\t'<<"-------"<<'\t'<<"-------"<<endl; f1.open("d:\\aaa.txt",ios::in); while(!f1.eof()) { f1>>Name>>Fam>>Tell; if(!strcmp(SearchFam,Fam)) cout<<Name<<'\t'<<Fam<<'\t'<<Tell<<endl; } }

  18. ذخیره و بازیابی در C++ #include<iostream.h> #include<fstream.h> #include<string.h> main() { fstream f1; int Menu; char Name[20]; char Fam[30]; char Tell[20]; char Search[30]; cout <<"Enter Choise:"<<endl; cout <<"1-Name"<<endl; cout <<"2-Fam"<<endl; cout <<"3-Tell"<<endl; cout <<"Select Menu:";cin >> Menu; cout<<"Enter Item for search = "; cin>>Search; f1.open("d:\\aaa.txt",ios::in); cout<<endl; cout<<" Name "<<'\t'<<" Fam "<<'\t'<<" Tell "<<endl; cout<<"-------"<<'\t'<<"-------"<<'\t'<<"-------"<<endl; while(!f1.eof()) { f1>>Name>>Fam>>Tell; if(Menu==1) if(!strcmp(Search,Name)) cout<<Name<<'\t'<<Fam<<'\t'<<Tell<<endl; if(Menu==2) if(!strcmp(Search,Fam)) cout<<Name<<'\t'<<Fam<<'\t'<<Tell<<endl; if(Menu==3) if(!strcmp(Search,Tell)) cout<<Name<<'\t'<<Fam<<'\t'<<Tell<<endl; } }

More Related