std::rewind(3)
β¨ std::rewind(3) β std::rewind β¨
okay so this is the std::rewind(3) manual page, bestie, and it's literally all about sending a file stream back to the start π
πΈ NAME πΈ
std::rewind β std::rewind
fr fr, that's the name and that's the vibe.
π Synopsis π
Defined in header <cstdio>:
void rewind( std::FILE* stream );
Moves the file position indicator to the beginning of the given file stream.
The function is equivalent to std::fseek(stream, 0, SEEK_SET);, except that end-of-file and error indicators are cleared.
The function drops any effects from previous calls to ungetc.
π¦ Parameters π¦
streamβ file stream to modify
β Return value β
(none)
no return value, no drama, periodt π
π Example π
// Run this code
#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);
}
Output:
0123456789
size1 = 10
0123456789
size2 = 10
π See also π
fseekβ moves the file position indicator to a specific location in a file (function)- C documentation for
rewind
source: http://cppreference.com β version/date: 2024.06.10 β okay bye bestie, go rewind something iconic π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms