我写了个这样的例子:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(void)
{
int fd;
fd = open("txt",O_RDWR | O_CREAT | O_TRUNC );
if(fd == -1)
{
perror("open");
return -1;
}
printf("******");
dup2(fd,STDOUT_FILENO);
printf("######\n");
close(1);
return 0;
}
终端无输出,txt里“******######”,为什么呢
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(void)
{
int fd;
fd = open("txt",O_RDWR | O_CREAT | O_TRUNC );
if(fd == -1)
{
perror("open");
return -1;
}
printf("******");
dup2(fd,STDOUT_FILENO);
printf("######\n");
close(1);
return 0;
}
终端无输出,txt里“******######”,为什么呢