Chinaunix首页 | 论坛 | 博客
  • 博客访问: 584732
  • 博文数量: 141
  • 博客积分: 3425
  • 博客等级: 中校
  • 技术积分: 1609
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-23 15:55
文章分类

全部博文(141)

文章存档

2019年(5)

2011年(19)

2010年(36)

2009年(13)

2008年(50)

2007年(18)

分类: C/C++

2007-11-04 22:41:38

  FILE *freopen( const char * restrict filename, const char * restrict mode,
  FILE * restrict stream );



This function redirects a stream. Like fopen( ), freopen( ) opens the specified file in the specified mode. However, rather than creating a new stream, freopen( ) associates the file with the existing stream specified by the third argument. The file previously associated with that stream is closed. The most common use of freopen( ) is to redirect the standard streams, stdin, stdout, and stderr.

The freopen( ) function closes the file associated with the FILE pointer argument and opens the file with the specified name, associating it with the same FILE pointer as the file just closed. That FILE pointer is the function's return value. If an error occurs, freopen( ) returns a null pointer, and the FILE pointer passed to the function is closed.

The new access mode is specified by the second character string argument, in the same way described under fopen( ).




  FILE *tmpfile( void );



The tmpfile( ) function creates a new temporary file whose name is distinct from all other existing files, and opens the file for binary writing and reading (as if the mode string "wb+" were used in an fopen( ) call). If the program is terminated normally, the file is automatically deleted.

If tmpfile( ) is unable to open a temporary file, it returns a null pointer. Whether temporary files are deleted after an abnormal program termination depends on the given implementation. The C99 standard recommends that the maximum number of temporary files that can be created should be available in the macro TMP_MAX, which is defined in stdio.h and must be at least 25.



阅读(1125) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~