fopen command using "r" or "w"

조회 수: 15 (최근 30일)
Sina S
Sina S 2019년 3월 24일
댓글: Walter Roberson 2022년 4월 14일
Why do we need to read and write files? Could u kindly explain the following lines?
fopen(A, 'r')
fopen(B, 'w')

답변 (1개)

Image Analyst
Image Analyst 2019년 3월 24일
You don't need to. If you don't need to import data from a file and don't need to output data to a file, then you don't need to use those functions. Only use them if you need to import or export data. If you use them, be sure you also use fclose().
  댓글 수: 2
Giovanni Ponce
Giovanni Ponce 2022년 4월 14일
Could you explain what 'r' means when using it with fopen?
Walter Roberson
Walter Roberson 2022년 4월 14일
'r' requests "read" access to the file. 'r' is the default if you do not specify the kind of access you need. "r" by itself requests the default "binary" file access; if you want to treat the file as a text file (possibly created on Windows) request "rt" (Read, Text)
If you open a file for read access, then it is permitted to fseek() inside the file. However it is not possible to write to the file; attempting to write will either give an error or else the writes will simply not happen.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by