标准输出重定向到一个文件? [英] Redirect standard output to a file?

查看:123
本文介绍了标准输出重定向到一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写这将标准输出重定向到文件所在的文件名是一个函数名.log,其中name是函数参数

I want to write a function which would redirect the standard output to a file where the name of the file is "name".log where "name" is the argument to the function

void redirect(char *name) {

我不知道从哪里开始。

I don't know where to begin.

推荐答案

您可以使用的 则freopen()

You can use freopen()

// code copied from the link
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
...

这篇关于标准输出重定向到一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆