មេរៀនទី១១ FILE C/C++ for beginner រៀបចំ និងបង្រៀនដោយ៖ អ៊ិន សុភា

Slides:



Advertisements
Similar presentations
File I/O in C++. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk);is stored on a secondary storage device.
Advertisements

File I/O Finished off Colin Cherry standing in for Dr. Lin.
FILE OPEN MODES File open modes n ios::app n ios::ate n ios::binary n ios::in n ios::out n ios::trunc n ios::nocreate n ios::noreplace.
Copyright © 2012 Pearson Education, Inc. Chapter 12: Advanced File Operations.
File Handling Accessing a data file for input: 1) Include the file stream header file: #include using namespace std; 2) Associate an input file name with.
17 File Processing. OBJECTIVES In this chapter you will learn:  To create, read, write and update files.  Sequential file processing.  Random-access.
DATA FILE HANDLING. Contents to be covered in class  Concept of files & streams  Stream class hierarchy  File handling functions  Text V/S Binary.
1 File I/O In C++, I/O occurs in streams. A stream is a sequence of bytes Each I/O device (e.g. keyboard, mouse, monitor, hard disk, printer, etc.) receives.
Two Ways to Store Data in a File Text format Binary format.
File Organization and Processing CS nd Term Basic file operations Cairo University Faculty of Computers and Information.
Darbas su failais Arnas Terekas IT 1gr. Vilniaus universitetas Matematikos ir informatikos fakultetas.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Topics 1.File Basics 2.Output Formatting 3.Passing File Stream Objects to Functions 4.More Detailed Error Testing 5.Member Functions for Reading and 6.Writing.
Advanced File Operations Chapter File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 12: Advanced File Operations.
Monday, Mar 31, 2003Kate Gregory with material from Deitel and Deitel Week 12 Labs 4 and 5 are back File IO Looking ahead to the final.
File I/O. fstream files File: similar to vector of elements Used for input and output Elements of file can be –character (text)struct –object (non-text.
C++ FILE I/O.
File I/O in C++ II. Open() function Open() is a member function in each classes ( fstream, ifstream, ofstream) Void fstream :: open ( const char *filename,
FILE I/O IN C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
C++ Programming: chapter 6 – iostream 2014, Spring Pusan National University Ki-Joune Li 1.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 12 Advanced File Operations.
DCT1063 Programming 2 CHAPTER 3 FILE INPUT AND FILE OUTPUT Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Member Functions for Reading and Writing Files 12.5.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 1 due Friday, 7pm. RAD due next Friday. Presentations week 6. Today: –More details on functions,
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
File Processing Files are used for data persistance-permanent retention of large amounts of data. Computer store files on secondary storage devices,such.
C++ Programming: chapter 6 – iostream 2015, Spring Pusan National University Ki-Joune Li 1.
Declaring fstream Objects An istream object named cin connects program and keyboard An ostream object named cout connects the program and the screen These.
Learners Support Publications Working with Files.
CSCI 333 Data Structures I/O with C++ 20 October, 2003.
Lecture 14 Arguments, Classes and Files. Arguments.
Binary Files. Text Files vs. Binary Files Text files: A way to store data in a secondary storage device using Text representation (e.g., ASCII characters)
 Working with multiple files  Copying files  Updating files.
File I/O in C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
Advanced File Operations Chapter File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to.
Ms N Nashandi Dr SH Nggada 2016/01/03Ms N Nashandi and Dr SH Nggada1 Week 6 -File input and output in C++
Lecture 2 Fundamental File: Processing Operations
Programming II I/O Streams and Data Files 1(c) Asma AlOsaimi.
CS212: Object Oriented Analysis and Design
Chapter 14: Sequential Access Files
File Processing.
17 File Processing.
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Writing and Reading Raw Data
What is a File? A file is a collection on information, usually stored on a computer’s disk. Information can be saved to files and then later reused.
C ++ MULTIPLE CHOICE QUESTION
CISC/CMPE320 - Prof. McLeod
FILE HANDLING IN C++.
Basic File I/O and Stream Objects
17 File Processing.
آشنایی با ساختارها و کار با فایلها
files Dr. Bhargavi Goswami Department of Computer Science
Today’s Lecture I/O Streams Tools for File I/O
Chapter 13: Advanced File and I/O Operations
Sequential input and output Operations in file
C++ FileIO pepper.
Topics Input and Output Streams More Detailed Error Testing
Chapter 12: Advanced File Operations.
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Data File Handling in C++
C++ Programming: chapter 6 – iostream
Data File Handling RITIKA SHARMA.
File Streams 12/09/13.
File Handling Accessing a data file for input: 1) Include the file stream header file: #include using namespace std; 2) Associate an input file.
File I/O in C++ II.
មេរៀនទី៧ Pointer C/C++ for beginner រៀបចំ និងបង្រៀនដោយ៖ អ៊ិន សុភា
Presentation transcript:

មេរៀនទី១១ FILE C/C++ for beginner រៀបចំ និងបង្រៀនដោយ៖ អ៊ិន សុភា C# Database C/C++ for beginner មេរៀនទី១១ FILE រៀបចំ និងបង្រៀនដោយ៖ អ៊ិន សុភា Tel: 097 200 13 99 / 016 270 878 Email: insophea1987@gmail.Com

C/C++ for beginner អ្នកពិតជាបានដឹងហើយថាការផ្ទុកទិន្នន័យជាមួយ variables វានឹងមិនអាចស្ថិតស្ថេរបាន​ឡើយព្រោះ ថាទិន្នន័យនឹងបាត់បង់ទៅវិញនៅពេលដែលកម្មវិធីត្រូវបានបិទ ហើយអ្នកត្រូវតែបញ្ចូលទិន្នន័យទាំងនោះឡើងវិញរៀងរាល់ពេលដែលកម្មវិធីដំណើរការ។

C/C++ for beginner ដើម្បីរក្សាទុកទិន្នន័យអោយបានជាអចិន្រ្តៃយ៏យើងត្រូវតែធ្វើការប្រមូលផ្តុំទិន្នន័យទាំងនោះទៅជា file និងមានទីតាំងជាក់លាក់ណាមួយនៃ Storage ដូចជា HDD, External HDD, Flash​ ជាដើម។ សម្រាប់កម្មវិធីគ្រប់គ្រងទិន្នន័យធំៗ វាក៏នឹងតម្រូវឱ្យយើងរក្សាទុកវាជាមួយប្រព័ន្ធគ្រប់គ្រងទិន្នន័យ(DBMS) ដែលអ្នកអាចសិក្សាបាននៅវគ្គបន្ទាប់ ។

ការបង្កើត File C/C++ for beginner fstream ជា class ដែលមាននៅក្នុង <fstream> header objectName ជាឈ្មោះ object ដែលតំណាងឱ្យ External File ដែលត្រូវធ្វើការលើ Memory open() ជា function ប្រើសម្រាប់បើក ឬ បង្កើត File ថ្មី “fileName” ជាការកំណត់ឈ្មោះ និងទីតាំង file ដែលនឹងត្រូវបើក ឬបង្កើតថ្មី fileMode ជាការបញ្ជាក់ អំពី ប្រភេទ File ដែលត្រូវធ្វើការជាមួយ fstream objectName; objectName.open("fileName",fileMode);

ios::out (បង្កើត File ថ្មីសម្រាប់រក្សារទុកទិន្នន័យ) C/C++ for beginner FileMode ios::out (បង្កើត File ថ្មីសម្រាប់រក្សារទុកទិន្នន័យ) ios::in (ទាញទិន្នន័យពី File ដែលមានស្រាប់) ios::app (បន្ថែមទិន្នន័យទៅកាន់ File ដែលមានស្រាប់) ios::binary (ប្រភេទ File ជា binary)

យកទិន្នន័យទុកក្នុង File C/C++ for beginner យកទិន្នន័យទុកក្នុង File fstream objectName; objectName.open("fileName",fileMode); objectName.write(&data,sizeof(data)); obejectName.close(); write() ជា function សម្រាប់ យកទិន្នន័យទៅទុកក្នុង file ហើយវាទាមទារឱ្យយើងបោះនូវ ទិន្នន័យ ព្រមទាំងបញ្ជាក់ពី ទំហំ byte សរុបរបស់ទិន្នន័យទាំងនោះផងដែរ។ ទិន្នន័យដែលត្រូវទុកក្នុង file ត្រូវមានទំហំប៉ុនៗគ្នា។ close() ជា function សម្រាប់ផ្តាច់ Stream ពី file និង memory

Example1: write string value to binary file fstream writer; writer.open("d:\\test.txt",ios::out | ios::app | ios::binary); char text[100]="Hello1\nHello2"; writer.write((char*)&text,sizeof(text)); writer.close(); getch();

C/C++ for beginner Example2: write integer value to text file int number=8; fstream writer; writer.open("d:test.txt",ios::out|ios::app); writer<<number; writer.close(); getch();

C/C++ for beginner ទាញទិន្នន័យពី File fstream objectName; objectName.open("fileName",fileMode); objectName.read(&data,sizeof(data)); obejectName.close(); read() ជា function សម្រាប់ទាញទិន្នន័យពី file មកផ្ទុកលើ memory ហើយវាក៏ទាមទារឱ្យមាន variable មួយសម្រាប់ចាំទទួលផងដែរ។ ត្រូវបញ្ជាក់ពី ទំហំ record នីមួយនៅក្នុង file

reader.open("d:test.txt",ios::in | ios::binary); Example1: read string value from binary file fstream reader; char getStr[100]; reader.open("d:test.txt",ios::in | ios::binary); while(reader.read((char*)&getStr,sizeof(getStr))) cout<<getStr<<endl; reader.close();

C/C++ for beginner Example2: read integer value from text file string line; fstream reader; reader.open("d:test.txt",ios::in); while(getline(reader,line)) cout<<line<<endl; reader.close(); getch();