Without using printf and cout how can we display any thing?

Dani AI

Generated

asked a good basic question and the quick suggestions from and point to the usual alternatives. In short: there are multiple ways to produce output besides printf and cout, and the right choice depends on whether the program is C or C++, whether formatting is needed, and whether buffered versus unbuffered I/O is acceptable.

For C: use the standard string/byte writers for simple output, or the block writer when sending binary or prebuilt buffers. When formatted text is needed but printf is to be avoided, format into a local buffer (safe formatting routines) and hand that buffer to a writer. For POSIX programs that need immediate, unbuffered output, use the low-level system write call instead of stdio. See the C library pages for string and block output and the POSIX write manual for details (fputs, fwrite, write(2)).

For C++: use stream member write or an ostringstream to construct output, and prefer diagnostic streams for messages that must not be delayed. Modern alternatives such as the {fmt} library provide safe, convenient formatting and printing (fmt). Remember buffering rules (stdout is commonly line-buffered on terminals), flush explicitly for immediate display (fflush), and choose OS calls only when portability is not required.

Recommended Answers

All 2 Replies

Is it that time again?

Lemme guess some other exclusions
- puts
- putchar
- write

Write a character to stdout:
int putchar(int c);
from <stdio.h> or <cstdio> (in C++ only).
It's enough...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.