首页 > 其他 > 详细

输入输出重定向

时间:2016-12-31 00:22:45      阅读:235      评论:0      收藏:0      [点我收藏+]

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\n",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打印到标准输入(显示器上).
 

输入输出重定向

原文:http://www.cnblogs.com/AbcFly/p/6238514.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!