1 / 10

Përdorimi i fajllave në C++

Përdorimi i fajllave në C++. Klasifikime Sipas mënyrës së qasjes në fajllat: Fajlla mje qasje sekuenciale (Sequential-access files) Fajlla me qasje direkte (Direct-access files) Sipas mënyrës së ruajtjes së të dhënave Fajlla tekstuale (Text files) Fajlla binarë (Binary files) Elemente

chapa
Télécharger la présentation

Përdorimi i fajllave në C++

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. Përdorimi i fajllave në C++ Klasifikime • Sipas mënyrës së qasjes në fajllat: • Fajlla mje qasje sekuenciale (Sequential-access files) • Fajlla me qasje direkte (Direct-access files) • Sipas mënyrës së ruajtjes së të dhënave • Fajlla tekstuale (Text files) • Fajlla binarë (Binary files) Elemente • Klasa për hyrje/dalje (ios, istream, ostream, ifstream, iostream, ofstream, fstream) • Rrjedha të fajllave (File streams) - objekte të klasave për hyrje/dalje

  2. Fajlla me qasje sekuenciale • Të dhënat shkruhen si sekuenca bajtesh • Në një bajt ruhet një karakter: • Shifra: 0,1,2,3,4,5,6,7,8,9 • Shkronja: a,b,c,…,z, A,B,C,…,Z • Simbole speciale: +,-,*,/,!,@,#,&,…

  3. Shkruarja në fajll Deklarimi i objektit dhe hapja e fajllit dalës ofstream r(“f”, ios::out); ofstream r(“f”); ofstream – klasë dalëse;r – objekti(rrjedha);f – emri i fajllit dalës(shtegu)ios::out – regjimi i hapjes së fajllit për shkruarje Deklarimi i objektit para hapjes së fajllit dalës ofstream r;r.open(“f”, ios::out) ofstream r;r.open(“f”) Mbyllja e fajllit dalës r.close()

  4. Shkruarja në fajll //file1 #include <iostream> #include <fstream> using namespace std; int main(){ int k=77; double x=58.94; ofstream Dalje("C:/prog2/koha.txt",ios::out); // ofstream Dalje("C:/prog2/koha.txt"); Dalje<<k<<' '<<x; cout<<"Shkruarja ne fajll perfundoi"<<endl; return 0; } Dalje Shkruarja ne fajll perfundoi

  5. Leximi nga fajlli Deklarimi i objektit dhe hapja e fajllit hyrës ifstream r(“f”, ios::in); ifstream r(“f”); ifstream – klasë hyrëse;r – objekti(rrjedha);f – emri i fajllit hyrës(shtegu)ios::in – regjimi i hapjes së fajllit për lexim Deklarimi i objektit para hapjes së fajllit hyrës ifstream r;r.open(“f”, ios::in) ifstream r;r.open(“f”) Mbyllja e fajllit hyrës r.close()

  6. Leximi nga fajlli //file2 #include <iostream> #include <fstream> using namespace std; int main(){ int k; double x; ifstream Hyrje("C:/prog2/koha.txt",ios::in); // ifstream Hyrje("C:/prog2/koha.txt"); Hyrje>>k>>x; cout<<"Vlerat e lexuara nga fajlli\n" <<"k="<<k<<" x="<<x<<endl; return 0; } Dalje Vlerat e lexuara nga fajlli k=77 x=58.94

  7. Leximi nga fajlli //file2a #include <iostream> #include <fstream> using namespace std; int main(){ int k; double x; ifstream Hyrje; Hyrje.open("C:/prog2/koha.txt",ios::in); // Hyrje.open("C:/prog2/koha.txt“); Hyrje>>k>>x; cout<<"Vlerat e lexuara nga fajlli\n" <<"k="<<k<<" x="<<x<<endl; return 0; } Dalje Vlerat e lexuara nga fajlli k=77 x=58.94

  8. Kontrollimi i hapjes së fajllit //file2g //file2g #include <iostream> #include <fstream> using namespace std; int main(){ int k; double x; ifstream Hyrje("F:/prog2/f1.txt"); //F: (gabim) if(Hyrje){ Hyrje>>k>>x; cout<<"Vlerat e lexuara nga fajlli\n" <<"k="<<k<<" x="<<x<<endl; } else { cout<<"Gabim gjate hapjes se fajllit"; } return 0; }

  9. Shkruarja në disa fajlle njëkohësisht //file1b #include <iostream> #include <fstream> using namespace std; int main(){ int k=77; double x=58.94; ofstream Dalje1("C:/prog2/f1.txt"); ofstream Dalje2("C:/prog2/f2.txt"); Dalje1<<k<<' '<<x; Dalje2<<x<<' '<<k; cout<<"Shkruarja ne fajllat perfundoi"<<endl; return 0; Dalje Shkruarja ne fajllat perfundoi

  10. Flamujt e statusit (Status flags) FLAMUJT E STATUSIT TË OBJEKTEVE TË RRJEDHAVE TË FAJLLAVE FUNKSIONET PËR MARRJE TË VLERAVE TË FLAMUJVE TË STATUSIT

More Related