您的位置:首页 > 运维架构 > Linux

求Linux C++高手解答

2011-08-04 19:57 267 查看
问题如下,今天整天就耗在和它有关的地方上了……

#include<stdio.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#include<fcntl.h>

void main()
{
char *buf="hello\n";
int len=strlen(buf);
close(1);
FILE* fd0=freopen("/dev/tty","w",stdout);
write(1,buf,len+1);
//如果close(1),然后没有调用freopen,然后直接write就会发生bad file descriptor的错误,结论正确!
//如果没有调用close(1),也没有调用freopen,然后直接write,则会成功输出到shell,结论正确!
//如果调用close(1)后再调用reopen,然后调用write,则会发生bad file descripto的错误,但是shell会显示所写的内容,神马意思??? 我要问的就是这里

FILE *fd=fopen("tmp.log","r+");
if(fd!=NULL)
fputs(strerror(errno),fd);
fclose(fd);
}

谢谢!

被移出首页,这个问题看来只能自己解了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: