std:: rewind
From cppreference.net
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
C-style I/O
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cstdio>
|
||
|
void
rewind
(
std::
FILE
*
stream
)
;
|
||
将文件位置指示器移动到给定文件流的起始位置。
该函数等效于 std:: fseek ( stream, 0 , SEEK_SET ) ; ,不同之处在于会清除文件结束和错误指示器。
该函数会丢弃之前调用 ungetc 所产生的所有效果。
目录 |
参数
| stream | - | 要修改的文件流 |
返回值
(无)
示例
运行此代码
#include <array> #include <cstdio> int main() { std::FILE* f = std::fopen("file.txt", "w"); for (char ch = '0'; ch <= '9'; ch++) std::fputc(ch, f); std::fclose(f); std::array<char, 20> str; std::FILE* f2 = std::fopen("file.txt", "r"); const unsigned size1 = std::fread(str.data(), 1, str.size(), f2); std::puts(str.data()); std::printf("size1 = %u\n", size1); std::rewind(f2); const unsigned size2 = std::fread(str.data(), 1, str.size(), f2); std::puts(str.data()); std::printf("size2 = %u", size2); std::fclose(f2); }
输出:
0123456789 size1 = 10 0123456789 size2 = 10
参见
|
将文件位置指示器移动到文件中的特定位置
(函数) |
|
|
C 文档
关于
rewind
|
|