zoukankan      html  css  js  c++  java
  • C头文件之<stdio.h>

    (stdio.h)

    该头文件主要是执行输入输出操作。文件中重要的概念是“流”(streams)。“流”在函数库中用FILE表示,用指针类型FILE *来操作。有三个标准流:stdin, stdout,和stderr。这三个都是FILE*变量。他们被编译器自动创造。在下面的函数中,strean形参都可以被赋值为标准流。 下面是重要函数:
    格式化输入输出

    printf、scanf
    这两个函数是最基本的函数了,从stdin读入,从stdout读出。
    fprintf
    函数原型:int fprintf(FILE* stream, const char * format, ...);。向参数stream指定的流格式化写入。stream可以是文件指针,也可以是stdin。
    fscanf
    函数原型:int fscanf ( FILE * stream, const char * format, ... );。从参数stream指定的流格式化读入。stream可以是文件指针,也可以是stdout。
    sscanf
    函数原型:int sscanf ( const char * s, const char * format, ...);。从参数s指定的字符串中格式化读入。就相当于将scanf的读入来源从stdin换为s。
    sprintf
    函数原型:int sprintf (char * str, const char * format, ...);。向参数s指定的字符串中格式化写入。就相当于将printf的写入去向从stdout换为s。


    文件入口

    freopen
    FILE * freopen ( const char * filename, const char * mode, FILE * stream );。将参数stream关联的流,改变为文件filename。参数mode指定文件读取模式。该函数在调试过程中可以将stdin指定为文件,这样避免浪费时间在输入上。
    /* freopen example: redirecting stdout */
    #include <stdio.h>
    
    int main ()
    {
      freopen ("myfile.txt","w",stdout);
      printf ("This sentence is redirected to a file.");
      fclose (stdout);
      return 0;
    }
  • 相关阅读:
    「JOISC 2020 Day3」收获
    $ ext{Min25}$筛
    [做题记录-图论] [NEERC2017]Journey from Petersburg to Moscow [关于处理路径前$k$大的一种方法]
    [复习笔记]一些有意思的解法技巧 (转 Dpair
    [比赛记录] CSP2021-S 题解
    [转]C++学习心得
    Sigmoid function in NN
    Kernel Regression from Nando's Deep Learning lecture 5
    Python codes
    php中mail()改用msmtp发送邮件
  • 原文地址:https://www.cnblogs.com/xyqhello/p/3705087.html
Copyright © 2011-2022 走看看