std::fputc,std::putc(3)
๐ NAME ๐
std::fputc,std::putc โ bestie, the NAME section is literally std::fputc,std::putc again, and honestly? Iconic behavior ๐
โจ
๐ธ Synopsis ๐ธ
Defined in header <cstdio>:
int fputc( int ch, std::FILE* stream );
int putc( int ch, std::FILE* stream );
So here's the tea: this writes a character ch to the given output stream stream. ๐ซถ
Internally, that character gets converted to unsigned char just before it's written. No cap, that's the whole conversion moment right before the write.
In C, putc() may be implemented as a macro, which is disallowed in C++. Therefore, calls to std::fputc() and std::putc() always have the same effect. Periodt. โจ
๐ Parameters ๐
chโ the character to be written ๐streamโ the output stream ๐
๐ฅ Return value ๐ฅ
- On success, it returns the written character. Slay. โ
- On failure, it returns
EOFand sets the error indicator (seestd::ferror()) onstream. ๐ญ๐
๐ฆ Example ๐ฆ
The page says // Run this code, so literally go run it bestie:
#include <cstdio>
int main()
{
for (char c = 'a'; c != 'z'; c++)
std::putc(c, stdout);
// putchar's return value is not equal to the argument
int r = 0x102A;
std::printf("\nr = 0x%x\n", r);
r = std::putchar(r);
std::printf("\nr = 0x%x\n", r);
}
๐ฎ Possible output
abcdefghijklmnopqrstuvwxy
r = 0x102A
*
r = 0x2A
๐ See also ๐
putcharwrites a character tostdout(function) ๐- C documentation for
fputc,putc๐
Signing off with source/version cppreference.com and date 2024.06.10 for page std::fputc,std::putc(3) โ bye bestie, go write some characters ๐๐งโจ
๐ฆ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms