Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To print something without using cout, printf or puts()

Tags:

c++

c

I had learned that

inline ostream & _Cdecl ostream::operator<< (const signed char * _s) {
    outstr(_s, (const signed char *)0);
    return *this;
}

is how the insertion operator (<<) is declared(overloaded) in the iostream.h header file. Can I possibly use the same function to print a string value on screen?

I tried

#include<iostream.h>
int main() {
    outstr("Hello world!", (const signed char *)0);
    return 0;
}

it ended up in error. I would like to use something like this in order to see if there is some possible way to answer this query of printing something on screen without using printf, cout or puts().

Update: I would welcome if you have any suggestions other than

#include<stdlib.h>
void main() {
    system("echo /"Hello world!/"");
}

NB: I have no restrictions if you can provide the C equivalent code that can print without a printf(), cout or puts()

like image 618
Praveen Vinny Avatar asked Dec 15 '22 16:12

Praveen Vinny


1 Answers

Yes you could call the function directly, however your reasoning to do so is flawed. The time you save by eliminating the subroutine call to the operator is negligible when compared to the time taken to perform the actual function; this would be like closing the windows of your car while the convertible roof is down in order to reduce the rain.

like image 131
mah Avatar answered Jan 05 '23 01:01

mah