1 / 8

FILE dan STREAM

FILE dan STREAM. Teknik Pemrograman Terstruktur 2. OPERAS DASAR FILE. Membuka atau mengaktifkan File Melaksanakan pemroresan file Menutup file. Definisi File : sebuah stream yang disimpan dalam media penyimpanan luar. Definisi STREAM.

Download Presentation

FILE dan STREAM

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. FILE dan STREAM Teknik Pemrograman Terstruktur 2

  2. OPERAS DASAR FILE • Membuka atau mengaktifkan File • Melaksanakan pemroresan file • Menutup file Definisi File : sebuah stream yang disimpan dalam media penyimpanan luar

  3. Definisi STREAM • suatu logika device yang menghasilkan dan menerima informasi atau wadah yang digunakan untuk menampung keluaran dan menampung aliran data

  4. Class yang dapat digunakan untuk mengelola file • ofstream  : Stream class untuk menulis ke file  • ifstream: Stream class untuk membaca dari file  • fstream : Stream class untuk membaca/menulis  dari/kefile

  5. Sintaks • Menulis ke file : nama_obyek << “tulisan/variabel”;  • Menutup file : nama_obyek.close(); • Menambah data pada file : ios::app pada open() • Memeriksa status file : • ‐ bad()  akan mengembalikan nilai true jika proses baca/tulis ke file gagal  • ‐ fail()  akan mengembalikan nilai jika terjadi kesalahan format  • ‐ eof()  akan mengembalikan nilai true jika akhir file tercapai pada saat proses pembacaan data  • Untuk membersikan flag : clear()

  6. Contoh Program • #include <iostream> • #include <conio> • #include <stdio> • #include <fstream> • void main() • { ofstream fileteks; • fileteks.open("D:\contoh.txt"); • fileteks.put('A'); • fileteks.put('B'); • fileteks.put('C'); • fileteks.close(); • getch(); • }

  7. Contoh program membuat file • #include <iostream> • #include <conio> • #include <stdio> • #include <fstream> • int main () • { • ofstream myfile; • myfile.open ("D:\contoh.txt"); • myfile << "Menulis baris pertama.\n"; • myfile << "Menulis baris kedua.\n"; • myfile << "Menulis baris ketiga.\n"; • myfile << "Menulis baris keempat.\n"; • myfile.close(); • }

More Related