std::freopen
From cppreference.com
Defined in header
<cstdio>
|
||
Reassigns an existing file stream stream
to a different file identified by filename
using specified mode. mode
is used to determine the new file access mode.
Contents |
[edit] Parameters
filename | - | file name to associate the file stream to | ||||||||||||||||||||||||||||||||||||||||
mode | - | null-terminated character string determining new file access mode
|
||||||||||||||||||||||||||||||||||||||||
stream | - | the file stream to modify |
[edit] Return value
stream
on success, NULL on failure
[edit] Example
The following code redirects stdout
to a file
Run this code
#include <cstdio> int main() { std::printf("stdout is printed to console"); std::freopen("redir.txt", "w", stdout); std::printf("stdout is redirected to a file"); std::fclose(stdout); }
Output:
stdout is printed to console
[edit] See also
opens a file (function) |
|
closes a file (function) |
|
C documentation for freopen
|