std::freopen
From cppreference.com
Defined in header
<cstdio>
|
||
FILE *freopen( const char *filename, const char *mode, FILE *stream );
|
||
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
#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) |
|