函式
<cstdio>

rewind

void rewind ( FILE * stream );
設定流的當前位置到檔案開始
stream關聯的位置指示器設定到檔案開始.

成功呼叫本函式後,stream 的檔案結束和錯誤內部指示器會被清除,並且此前所有對該stream 呼叫 ungetc 的效果都會被丟棄.

在以更新模式(讀+寫)開啟的流上,呼叫rewind允許在讀取和寫入之間切換。

引數

stream
指向一個 FILE 物件的指標,該物件標識了流。

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* rewind example */
#include <stdio.h>

int main ()
{
  int n;
  FILE * pFile;
  char buffer [27];

  pFile = fopen ("myfile.txt","w+");
  for ( n='A' ; n<='Z' ; n++)
    fputc ( n, pFile);
  rewind (pFile);
  fread (buffer,1,26,pFile);
  fclose (pFile);
  buffer[26]='\0';
  puts (buffer);
  return 0;
}

建立一個名為myfile.txt的檔案用於讀寫,並用字母表填充。然後檔案被倒帶,讀取其內容並存儲在緩衝區中,然後寫入標準輸出.

ABCDEFGHIJKLMNOPQRSTUVWXYZ


另見