求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);
}
谢谢!
被移出首页,这个问题看来只能自己解了
#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);
}
谢谢!
被移出首页,这个问题看来只能自己解了
相关文章推荐
- 关于C++中 is a概念的一点疑问,希望高手解答。
- 为什么在C++中对赋值号“=”的重载只能使用成员函数而不可以使用友元函数?求高手、大神帮我解答!
- ubuntu 14.04 安装vim YouCompleteMe自动补全插件 Linux C/C++高手必备
- LINUX高手经验:Linux常见20个问题的详细解答
- LinuxC/C++编程基础(2) 基于boost::any构建数据容器
- Linux下编译C++
- Linux下,使用C/C++编写"静态链接库"的一个简单例子
- 在Linux平台下如何编译一个C++工程
- 用vs编写和调试linux C++程序
- Cross-Platform Development in C++: Building Mac OS X, Linux, and Windows Applications
- linux系统下通过jni用c++调用java
- linux下如何用GDB调试c++程序
- windows到linuxc++项目移植问题小结
- Linux下C++访问MySQL 【转】
- linux下C++进程内存增长问题的分析
- linux/eclipse/c++ 动态库的创立与调用
- Linux中C/C++动态库、静态库编译
- Linux下使用C/C++访问数据库——Oracle之OCI篇 推荐
- 高手进阶必读:Linux内核的同步机制
- Linux 下C++编写