Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::fputc,std::putc

      From cppreference.com
      <cpp‎ |io‎ |c
       
       
       
       
      Defined in header<cstdio>
      int fputc(int ch,std::FILE* stream);
      int putc(int ch,std::FILE* stream);

      Writes a characterch to the given output streamstream.

      Internally, the character is converted tounsignedchar just before being written.

      In C,putc() may be implemented as a macro, which is disallowed in C++. Therefore, calls tostd::fputc() andstd::putc() always have the same effect.

      Contents

      [edit]Parameters

      ch - character to be written
      stream - output stream

      [edit]Return value

      On success, returns the written character.

      On failure, returnsEOF and sets theerror indicator (seestd::ferror()) onstream.

      [edit]Example

      Run this code
      #include <cstdio> int main(){for(char c='a'; c!='z'; c++)        std::putc(c,stdout); // putchar's return value is not equal to the argumentint r=0x102A;std::printf("\nr = 0x%x\n", r);     r=std::putchar(r);std::printf("\nr = 0x%x\n", r);}

      Possible output:

      abcdefghijklmnopqrstuvwxyr = 0x102A*r = 0x2A

      [edit]See also

      writes a character tostdout
      (function)[edit]
      C documentation forfputc,putc
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/c/fputc&oldid=159797"

      [8]ページ先頭

      ©2009-2025 Movatter.jp