stdin,stdout 等类型为 FILE *。

STDIN_FILENO,STDOUT_FILENO,STDERR_FILENO 等类型为 int。

使用 FILE * 的函数主要有:fopen、fread、fwrite、fclose等,基本上都以 f 开头。

使用 STDIN_FILENO 等的函数有:open、read、write、close等。

stdin 等属于标准 I/O,高级的输入输出函数,定义在 <stdio.h>。

STDIN_FILENO 等是文件描述符,是非负整数,一般定义为0, 1, 2,直接调用系统调用,定义在 <unistd.h>。

fileno() 函数可以用来取得 stream 指定的文件流所使用的文件描述符:

#include <stdio.h>
#include <unistd.h> int main()
{
printf("%d \n",fileno(stdin)); //0
printf("%d \n",fileno(stdout)); //1
printf("%d \n",fileno(stderr)); //2 return 0;
}

接受标准输入,输出到标准输出:

#include <stdio.h>
#include <unistd.h> #define SIZE 100 int main()
{
int n;
char buf[SIZE]; while(n = read(STDIN_FILENO,buf,SIZE))
{
if(n != write(STDOUT_FILENO,buf,n))
perror("write error");
} if(n < 0)
perror("read error"); return 0;
}

stdin,stdout 和 STDOUT_FILENO,STDIN_FILENO的更多相关文章

  1. stdin stdout stderr - 标准 I/O 流

    Fd #include <stdio.h> Fd extern FILE *stdin; Fd extern FILE *stdout; Fd extern FILE *stderr; D ...

  2. vbs脚本要求在cmd中输入输出用StdIn ,StdOut

    Dim StdIn, StdOutSet StdIn = WScript.StdInSet StdOut = WScript.StdOut Do While Not StdIn.AtEndOfStre ...

  3. WorkerMan源码分析(resetStd方法,PHP中STDIN, STDOUT, STDERR的重定向)

    WorkerMan中work.php中 resetStd 方法中代码如下 public static function resetStd() { if (!static::$daemonize || ...

  4. stdin stdout stderr 标准I/O流

    Unix中一切皆文件,磁盘等设备在操作系统来看都是文件. 对文件进行操作时,需要打开这个文件,并获得文件描述符(file descriptor, fd) 而每个进程生来就有三个文件描述符绑定在它身上, ...

  5. shell基础知识之 stdin,stdout,stderr和文件描述符

    stdin,stdout,stderr stdin=0 stdout=1 stderr=2 使用tee来传递内容,把stdout 作为stdin 传到下个命令 root@172-18-21-195:/ ...

  6. 以冒泡排序为例--malloc/free 重定向stdin stdout

    esort.c 代码如下,可关注下mallloc/free,freopen重定向的用法,排序为每轮将最小的数放在最前面: #include<stdio.h> #include<mal ...

  7. [LINK]php的三种CLI常量:STDIN,STDOUT,STDERR

    FROM : http://www.cnblogs.com/thinksasa/archive/2013/02/27/2935158.html PHP CLI(command line interfa ...

  8. 【转】stdin, stdout, stderr 以及重定向

    详细见: http://my.oschina.net/qihh/blog/55308 stdin是标准输入文件,stdout是标准输出文件,stderr标准出错文件. 程序按如下方式使用这些文件: 标 ...

  9. 重定向stdin stdout stderr |

    在Linux下,当一个用户进程被创建的时候,系统会自动为该进程创建三个数据 流,也就是题目中所提到的这三个.那么什么是数据流呢(stream)? 我们知道,一个程序要运行,需要有输入.输出,如果出错, ...

随机推荐

  1. CF1234A Equalize Prices

    洛谷 CF1234A Equalize Prices Again 洛谷传送门 题目描述 You are both a shop keeper and a shop assistant at a sma ...

  2. 20190922 「HZOJ NOIP2019 Round #7」20190922模拟

    综述 这次是USACO2019JAN Gold的题目. \(\mathrm{Cow Poetry}\) 题解 因为每句诗的长度一定是\(k\),所以自然而然想到背包. 设\(opt[i][j]\)代表 ...

  3. js replace方法第二个参数,远不止你想的那么强大

    js replace() 方法,想必大家都不陌生. 定义和用法: replace()方法用于在字符串中用一些字符替换另一些字符,或者替换一个与正则表达式匹配的子串. stringObject.repl ...

  4. oracle 块速查

    头信息区 这个区包括数据块的地址,数据块类型,检查点信息,scn信息等信息. --------- Start minblk maxblk buffer tsn: rdba: ) scn: 0x0000 ...

  5. C/C++深度优先搜索(递归树模拟)

    //C++深度优先搜索(递归树模拟) #define _CRT_SECURE_NO_WARNINGS #include <iostream> #define MAX_N 1000 usin ...

  6. 第八节:EF Core连接MySql数据库

    一. 前提 1.安装EF Core连接MySQL的驱动,这里有两类: (1).Oracle官方出品:MySql.Data.EntityFrameworkCore (版本:8.0.17) (2).其他第 ...

  7. 不依赖Spring使用AspectJ达到AOP面向切面编程

    网上大多数介绍AspectJ的文章都是和Spring容器混用的,但有时我们想自己写框架就需要抛开Spring造轮子,类似使用原生AspectJ达到面向切面编程.步骤很简单,只需要两步. 1.导入依赖 ...

  8. navicat for mongodb12破解

    网上搜了一圈,都不管用.大多都有病毒,最后还是通过搜索github解决问题. 破解文件:https://github.com/DoubleLabyrinth/navicat-keygen/releas ...

  9. python爬取豆瓣电影首页超链接

    什么是爬虫?  我们可以把互联网比作一张大网,而爬虫(即网络爬虫)便是在网上爬行的蜘蛛.把网的节点比作一个个网页,爬虫爬到这就相当于访问了该页面,获取了其信息.可以把节点间的连线比作网页与网页之间的链 ...

  10. Java反射获取泛型类型

    本文链接:https://blog.csdn.net/hongxingxiaonan/article/details/49202613 在Java反射技术的应用中,取得一个类的成员.方法和构造函数相对 ...