Пространства имён
Варианты
Действия

std::freopen

Материал из cppreference.com
< cpp‎ | io‎ | c

 
 
Библиотека ввода/вывода
Манипуляторы ввода/вывода
Функции print(C++23)
Ввод/вывод в стиле C
Буферы
(устарело в C++98)
Потоки
Абстракции
Файловый ввод/вывод
Ввод/вывод строк
Ввод/вывод массивов
(устарело в C++98)
(устарело в C++98)
(устарело в C++98)
Синхронизированный вывод
Типы
Интерфейс категорий ошибок
(C++11)
 
Ввод/Вывод в стиле C
Типы и объекты
Функции
Доступ к файлам
Прямой ввод/вывод
Неформатированный ввод/вывод
Форматированный ввод
(C++11)(C++11)(C++11)    
(C++11)(C++11)(C++11)    
Форматированный вывод
Позиционирование файла
Обработка ошибок
Операции с файлами
 
Определено в заголовочном файле <cstdio>
FILE *freopen(constchar*filename, constchar*mode, FILE *stream );
Переназначает существующих stream поток файла в другой файл, определенных filenameusing заданном режиме. mode используется для определения нового режима доступа к файлу.
Оригинал:
Reassigns an existing file stream stream to a different file identified by filenameusing specified mode. mode is used to determine the new file access mode.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

Содержание

[править]Параметры

filename
имя файла, чтобы связать файл потока
Оригинал:
file name to associate the file stream to
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
mode
нулем строку символов определении нового режима доступа к файлу
File access
mode string
Meaning Explanation Action if file
already exists
Action if file
does not exist
"r" read Open a file for reading read from start failure to open
"w" write Create a file for writing destroy contents create new
"a" append Append to a file write to end create new
"r+" read extended Open a file for read/write read from start error
"w+" write extended Create a file for read/write destroy contents create new
"a+" append extended Open a file for read/write write to end create new
File access mode flag "b" can optionally be specified to open a file in binary mode. This flag has effect only on Windows systems.
On the append file access modes, data is written to the end of the file regardless of the current position of the file position indicator.
Оригинал:
null-terminated character string determining new file access mode
File access
mode string
Meaning Explanation Action if file
already exists
Action if file
does not exist
"r" read Open a file for reading read from start failure to open
"w" write Create a file for writing destroy contents create new
"a" append Append to a file write to end create new
"r+" read extended Open a file for read/write read from start error
"w+" write extended Create a file for read/write destroy contents create new
"a+" append extended Open a file for read/write write to end create new
File access mode flag "b" can optionally be specified to open a file in binary mode. This flag has effect only on Windows systems.
On the append file access modes, data is written to the end of the file regardless of the current position of the file position indicator.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
stream
поток файла изменить
Оригинал:
the file stream to modify
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

[править]Возвращаемое значение

stream на успех, NULL на провал
Оригинал:
stream on success, NULL on failure
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

[править]Пример

Следующий код перенаправляет stdout в файл
Оригинал:
The following code redirects stdout to a file
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

#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);}

Вывод:

stdout is printed to console

[править]См. также

открывает файл
Оригинал:
opens a file
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

(функция)[править]
закрывает файл
Оригинал:
closes a file
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

(функция)[править]
close