Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Processing #12

Closed
jimin-kiim opened this issue Oct 25, 2022 · 6 comments
Closed

File Processing #12

jimin-kiim opened this issue Oct 25, 2022 · 6 comments

Comments

@jimin-kiim
Copy link
Owner

jimin-kiim commented Oct 25, 2022

@jimin-kiim
Copy link
Owner Author

File Processing Overview

  1. opening a file
    • text file? or binary file?
    • in the case of writing, is it appending mode? or truncating?
    • is file position automatic? or user-control?
  2. processing(reading/writing) file
  3. closing the file

@jimin-kiim
Copy link
Owner Author

jimin-kiim commented Oct 25, 2022

Text mode and Binary mode

  • generally, binary file processing method is used.
  • text mode is a kind of exceptional case
  • 129 in text mode : stored as 3 character, 3 bytes of memory (3 ASCII code; ASCII code 1 character : 1 byte)
  • 129 in binary mode(image, video, sound) : stored as 10000001, 1 byte of memory

@jimin-kiim
Copy link
Owner Author

jimin-kiim commented Oct 25, 2022

Specifying modes for member function 'open'

  • either using only one mode or combination of several modes( with 'or operator' | ) are available

Different Modes

  • ios::in
    opening the file as 'read-only' mode (considering the file as an input)
  • ios::out
    opening the file as 'write-only' mode (considering the file as a destination for output)
  • ios::binary
    opening the file in binay mode
  • ios::ate
    setting the initial position as the end of the file.
    unless this flag is set, the initial position is the beginning of the file.
  • ios::app
    performing output operation at the end of the file.
    appending the content to the current content of the file.
  • ios:: trunc
    if the file is opened for output operations and it already existed,
    then its previous content is deleted and replaced by the new one.

Default mode

ofstream : ios::out
ifstream : ios::in
fstream : ios::in|ios::out

@jimin-kiim
Copy link
Owner Author

jimin-kiim commented Oct 25, 2022

Get and Put Stream Positioning

reading - get, writing - put

  • tellg(), tellp()
    • returns the current get/put position
  • seekg(), seekp()
    • changes the location of the get/put position
    • seekg(position) or seekg(offset, direction)
    • modes
      • ios::beg : offset counted from the beginning of the stream
      • ios::cur : offset counted from the current position
      • ios::end : offset counted from the end of the stream

@jimin-kiim
Copy link
Owner Author

jimin-kiim commented Oct 25, 2022

Binary file processing and memblock

  • write( memory_block, size );
  • read( memory_block, size ); // the file is read as much as the 'size' bytes and stored into the 'memory_block'
  • memory block: is a pointer that points to some memory block
  • size: the unit of size if bytes

@jimin-kiim
Copy link
Owner Author

File Stream Class

  • ofstream(output file stream) : stream class to write on files
  • ifstream(input file stream) : stream class to read from files
  • fstream(file stream) : stream class to read and write from/to files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant