zoukankan      html  css  js  c++  java
  • stdin、stdout、stderr

    1 ferror

    2 stdin

    3 stdout

    4 stderr

    1 ferror

    功能:检测文件是否出现错误

    返值:未出错0,出错非0

    说明:每次调用文件输入输出函数,均产生一个新的ferror函数值,所以应及时测试

    fopen打开文件时,ferror函数初值自动置为0

     1 #define _CRT_SECURE_NO_WARNINGS
     2 
     3 #include<stdio.h>
     4 #include<stdlib.h>
     5 
     6 main()
     7 {
     8     FILE *pf;
     9 
    10     pf = fopen("E:\1.txt", "r");
    11 
    12     if (pf == NULL)
    13     {
    14         printf("fail");
    15     }
    16     else
    17     {
    18         printf("succes
    ");
    19 
    20         if (ferror(pf) == 0)
    21         {
    22             printf("normal
    ");
    23         }
    24         else
    25         {
    26             printf("error
    ");
    27         }
    28 
    29         fputs("hello", pf);
    30 
    31         if (ferror(pf) == 0)
    32         {
    33             printf("normal
    ");
    34         }
    35         else
    36         {
    37             printf("error
    ");
    38         }
    39     }
    40     
    41     system("pause");
    42 }

    2 stdin键盘

    3 stdout显示器

    4 stderr错误

     1 #define _CRT_SECURE_NO_WARNINGS
     2 
     3 #include<stdio.h>
     4 #include<stdlib.h>
     5 
     6 main()
     7 {
     8     //stderr始终在显示器,如果重定向,stdout会被写入磁盘
     9     //遇到错误,就可以把错误信息写入stderr,会自动在显示器上输出
    10     
    11     fprintf(stderr, "stderr你遇到的错误是%s,重试次数是%d
    ", "权限不够", 3);
    12 
    13     fprintf(stdout, "stdout你遇到的错误是%s,重试次数是%d
    ", "权限不够", 3);
    14 
    15     system("pause");
    16 }
  • 相关阅读:
    学习bn算法
    记录pytorch的几个问题
    Python: 你不知道的 super
    cmd里面怎么复制粘贴
    tensorflow的transpose
    应该做一个软件,直接把视频里面的英语,转换成字幕,然后翻译
    继续修改,爬虫贴吧,上次的每次只取一个图片.
    Deleting elements
    Map, filter and reduce
    List methods
  • 原文地址:https://www.cnblogs.com/denggelin/p/5517494.html
Copyright © 2011-2022 走看看