Namespaces
Variants

std:: fputc, std:: putc

From cppreference.net
< cpp ‎ | io ‎ | c
헤더 파일에 정의됨 <cstdio>
int fputc ( int ch, std:: FILE * stream ) ;
int putc ( int ch, std:: FILE * stream ) ;

주어진 출력 스트림 stream 에 문자 ch 를 기록합니다.

내부적으로, 문자는 기록되기 직전에 unsigned char 로 변환됩니다.

C에서는 putc ( ) 가 매크로로 구현될 수 있지만, 이는 C++에서 허용되지 않습니다. 따라서 std :: fputc ( ) std :: putc ( ) 호출은 항상 동일한 효과를 가집니다.

목차

매개변수

ch - 기록될 문자
stream - 출력 스트림

반환값

성공 시, 기록된 문자를 반환합니다.

실패 시, EOF 를 반환하고 stream error 표시자를 설정합니다( std::ferror() 참조).

예제

#include <cstdio>
int main()
{
    for (char c = 'a'; c != 'z'; c++)
        std::putc(c, stdout);
    // putchar의 반환값은 인자와 같지 않음
    int r = 0x102A;
    std::printf("\nr = 0x%x\n", r);
    r = std::putchar(r);
    std::printf("\nr = 0x%x\n", r);
}

가능한 출력:

abcdefghijklmnopqrstuvwxy
r = 0x102A
*
r = 0x2A

참고 항목

stdout에 문자를 씁니다 stdout
(함수)
C 문서 for fputc , putc