std::rewind
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cstdio> で定義
|
||
void rewind( std::FILE* stream ); |
||
ファイル位置指示子を指定されたファイルストリームの先頭に移動させます。
この関数は std::fseek(stream, 0, SEEK_SET); と同等ですが、ファイル終端ステータスおよびエラー指示子をクリアします。
この関数は ungetc の以前の呼び出しによるあらゆる効果を取り消します。
引数
| stream | - | 変更するファイルストリーム |
戻り値
(なし)
例
Run this code
#include <cstdio>
int main()
{
std::FILE *f;
char ch;
char str[20];
f = std::fopen("file.txt", "w");
for (ch = '0'; ch <= '9'; ch++) {
std::fputc(ch, f);
}
std::fclose(f);
std::FILE* f2 = std::fopen("file.txt", "r");
unsigned int size = std::fread(str, 1, 10, f2);
std::puts(str);
std::printf("\n%u\n",size);
std::rewind(f2);
unsigned int size2 = std::fread(str, 1, 10, f2);
std::puts(str);
std::printf("\n%u",size2);
std::fclose(f2);
}
関連項目
| ファイル位置指示子をファイル内の指定された位置に移動させます (関数) | |
rewind の C言語リファレンス
| |