#include <stdio.h>
FILE *freopen(const char *path, const char *mode, FILE *stream);
#include <stdio.h>
int main()
{
FILE *fp;
printf ("This is output to STDOUT\n");
fp = freopen("myfile.txt", "w+", stdout);
printf ("STDOUT is redirected to myfile.txt\n");
fclose(fp);
return (0);
}
> ./freopen
This is output to STDOUT
> cat myfile.txt
STDOUT is redirected to myfile.txt
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |