[TOC]
### 完成輸入輸出操作的C庫函數-C library to perform Input/Output operations
Input and Output operations can also be performed in C++ using the C Standard Input and Output Library (cstdio, known as stdio.h in the C language). This library uses what are called streams to operate with physical devices such as keyboards, printers, terminals or with any other type of files supported by the system. Streams are an abstraction to interact with these in an uniform way; All streams have similar properties independently of the individual characteristics of the physical media they are associated with.
Streams are handled in the cstdio library as pointers to FILE objects. A pointer to a FILE object uniquely identifies a stream, and is used as a parameter in the operations involving that stream.
There also exist three standard streams: stdin, stdout and stderr, which are automatically created and opened for all programs using the library.
***
翻譯:
在C++中的輸入輸出操作也可以使用C標準輸入輸出庫。這個庫使用“流”這個概念來處理物理設備的輸入輸出,如鍵盤,打印機,終端或者是系統支持的其他類型的文件。流是使用同一的方式,用來和這些設備交互的抽象概念。所有的流都有相似屬性,這些屬性獨立于這些物理設備各自所具有的特有屬性。
流處理文件對象的方式是使用指針。一個指向文件對象的指針唯一標識一個流,涉及到流的操作中,可以將其作為一個參數。
一共有三個標準輸入輸出流:stdin,stdout,stderr。這三個標準輸入輸出流是自動為所有使用該庫的程序自動打開的。
### 流屬性-Stream properties
Streams have some properties that define which functions can be used on them and how these will treat the data input or output through them. Most of these properties are defined at the moment the stream is associated with a file (opened) using the fopen function:
* Read/Write Access
Specifies whether the stream has read or write access (or both) to the physical media they are associated with.
* Text / Binary
Text streams are thought to represent a set of text lines, each one ending with a new-line character. Depending on the environment where the application is run, some character translation may occur with text streams to adapt some special characters to the text file specifications of the environment. A binary stream, on the other hand, is a sequence of characters written or read from the physical media with no translation, having a one-to-one correspondence with the characters read or written to the stream.
* Buffer
A buffer is a block of memory where data is accumulated before being physically read or written to the associated file or device. Streams can be either fully buffered, line buffered or unbuffered. On fully buffered streams, data is read/written when the buffer is filled, on line buffered streams this happens when a new-line character is encountered, and on unbuffered streams characters are intended to be read/written as soon as possible.
* Orientation
On opening, streams have no orientation. As soon as an input/output operation is performed on them, they become either byte-oriented or wide-oriented, depending on the operation performed (generally, functions defined in <cstdio> are byte-oriented, while functions in <cwchar> are wide-oriented). See cwchar for more info.
***
翻譯:流有很多屬性,這些屬性規定了哪些函數可以使用它們,以及這些函數如何通過流來處理數據的輸入和輸出(這里應該是說讀寫權限)。大部分這些屬性是在文件被打開的時候所定義的,我們一般使用fopen函數來打開文件:
* 讀寫權限
當前流是否有讀或者寫(或者兩者皆有)的權限,對當前物理設備。
* 文本/二進制
文本流表示了一串文本行,以換行符結束。文本流中會有某些字符轉義,這是為了適應某些特定文本格式下特殊字符的傳輸。另一方面,一個二進制流是一系列從物理設備中讀或者寫的字符,并沒有發生任何轉義,讀寫過程中字符是一一對應的。
* 緩存
一個緩存是指一塊內存區域,該區域存放在物理讀寫文件或者設備之前的數據。流緩存分為全緩存,行緩存和無緩存。全緩存中數據的讀寫發生在緩存變滿,行緩存流是當換行符鍵入的時候發生讀寫,無緩存流是盡可能去讀寫。
* 面向
在打開過程中,流并沒有指向(這里的指向是指面向字節還是面向寬字節)。(計算機網絡中有相關概念)
### 標識符-Indicators
Streams have certain internal indicators that specify their current state and which affect the behavior of some input and output operations performed on them:
* Error indicator
This indicator is set when an error has occurred in an operation related to the stream. This indicator can be checked with the ferror function, and can be reset by calling either to clearerr, freopen or rewind.
* End-Of-File indicator
When set, indicates that the last reading or writing operation performed with the stream reached the End of File. It can be checked with the feof function, and can be reset by calling either to clearerr or freopen or by calling to any repositioning function (rewind, fseek and fsetpos).
* Position indicator
It is an internal pointer of each stream which points to the next character to be read or written in the next I/O operation. Its value can be obtained by the ftell and fgetpos functions, and can be changed using the repositioning functions rewind, fseek and fsetpos.
***
流中有自己的內部標識符,用來標記當前狀態和一些輸入輸出操作的結果:
* 錯誤標識符
當流操作出錯的時候會用到,可以通過函數ferror來進行檢測,也可以通過函數clearerr,freopen,rewind來重置。
* 文件結束標識符
當最后讀寫流的操作到達文件結束時該標識符會被定義,可以通過feof相關函數進行檢測,也可以通過clearerr,freopen或者任何重定位函數來進行重置。
* 定位標識符
每個流的內部指針,指向下一個IO操作中的字符。它的值可通過函數ftell,fgetpos來獲取,也可以通過任意重定位函數進行重置。
- 大賽說明
- PAT乙集題庫
- 模板
- 1001.害死人的3n+1 c
- 1002.寫出這個數 c 02
- 1003.我要通過(20)c03
- 1004.成績排名 C 04
- 1005.繼續(3n+1)猜想 (25) c05
- 1006. 換個格式輸出整數 (15) c06
- 1007.素數對猜想 (20) C 07
- 1008. 數組元素循環右移問題 (20) c08
- 1009.說反話(20)c09
- 1010.一元多項式求導 (25) c10
- 1011. A+B和C(15)c11
- 1012.數字分類 C12
- 1013.數素數(20) C 13
- 1014.福爾摩斯的約會(20)c 14
- 1015.德才論c15
- 1016.部分A+B C 16
- 1018.錘子剪刀布c18
- 1023 組個最小數(20) C23
- 1024 科學計數法(20) C24
- 1025.反轉鏈表(25)C25
- 1026.程序運行時間(15)c 26
- 1027. 打印沙漏(20) C 27
- 1028 人口普查(20) C 01
- 1029. 舊鍵盤(20) C 01
- 1030.完美數列 C 04
- 1031. 查驗身份證(15) c05
- 1032. 挖掘機技術哪家強(20) c06
- 1033. 舊鍵盤打字(20) C 07
- 1034. 有理數四則運算 08
- 1035.插入和歸并 C 09
- 1036.跟奧巴馬一起編程(15)C18
- 1037.在霍格沃茨找零錢C 11
- 1039.到底買不買 C 13
- 1041.考試座位號(15)C03
- 1042。字符統計 C16
- 1044.火星數字 C 15
- 1046. 劃拳(15) C 01
- 1047.編程團體賽C18
- 1051.復數乘法(15) c24
- 1054. 求平均值 (20) C
- 1036. 跟奧巴馬一起編程(15) c10
- 1055.集體照 C 09
- 1050. 螺旋矩陣
- C語言
- assert.h
- stdio.h
- Operations on files
- File access
- Formatted input/output
- Character input/output
- Direct input/output
- File positioning
- Error-handling
- Macros
- 數據結構
- 算法
- 5月8日測試題目
- 喬棟
- 01申彥棟
- 02方常吉
- 03王永明
- 04劉果靜
- 05原曉曉
- 09牛錦江
- 10李澤路
- 11葛建輝
- 12程才耀
- 13王旭昕
- 16田鵬
- 15李新奇
- 24王翡
- 18高捷
- 07耿生年
- 05王進
- 25閆鑫炎
- 5月9日測試題目
- 熱身題庫
- L1-1
- L1-2
- L1-3
- L1-4
- L1-5
- L1-6
- L1-8
- L1-7
- L2-1
- L2-2
- L2-3
- L2-4
- L3-1
- L3-2
- L3-3