redirect.cpp
资源名称:src.rar [点击查看]
上传用户:cqgdffbw
上传日期:2021-04-27
资源大小:17k
文件大小:0k
源码类别:
驱动编程
开发平台:
Unix_Linux
- #include <iostream>
- #include <unistd.h>
- #include <cerrno>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- using namespace std;
- int main(int argc, char* argv[])
- {
- int fd;
- fd = open("test", O_RDWR | O_CREAT | O_TRUNC);
- if (fd < 0) {
- perror("open");
- exit(1);
- }
- cout << "file descriptor is " << fd << endl;
- write(3,"Hello,world",11);
- write(fd,"Hello,World",11);
- close(fd);
- return 0;
- }