输入输出重定向

0. C语言的标准输入输出

 stdin

 stdout

 stderr

1. 重定向到文件

 

 1 #include <stdio.h>
 2 
 3 int main(){
 4     char a[100];
 5     if(1==0){
 6         freopen("data.txt","w",stdout);
 7         printf("hello word");
 8     }else{
 9         freopen("data.txt","r",stdin);
10         
11         scanf("%s",a);
12         printf("%s
",a);
13     }
14     
15     return 0;
16 }

输出结果

data.txt
-------------------
hello word
-----------------------------

hello
请按任意键继续. . .

2. 方式二

重定向(windows):

若输入_Test.exe <data_in.txt >data_out.txt
则从data_in.txt把“hello”读到str中,在把str打印到data_out.txt中.
 
管道(linux, UNIX):
cmd下输入test_out.exe | test_in.exe
则将test_out中打印的内容(xxoo)作为test_in的输入,testin将xxoo打印到标准输入(显示器上).
 
原文地址:https://www.cnblogs.com/AbcFly/p/6238514.html