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

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



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()
share|improve this question
2 
"in the iostream.h header file" --> "in your iostream.h header file" –  Benjamin Lindley Dec 3 '12 at 17:34
 
You won't be saving any significant operation time by doing this. Also, if you want to print something without using cout, printf or puts, one solution you could try is invoking a system call. –  SidR Dec 3 '12 at 17:35
1 
@SidR when you first posted your comment I assumed you meant calling some system-specific function to the kernel's output routine (a low level call that things like printf, or the poster's outstr call might do). Calling the system() function to call echo would be a horrible horrible thing to do, and if the OP were to suggest this in an interview, he would not only fail to get the job, he would also suffer (insert ridiculous hyperbole here). – mah Dec 3 '12 at 17:53
3 
@SidR when you call system() you are spawning a new process, a terribly expensive operation if its purpose is only to output something. Generally (perhaps always, I am not certain), that process is a shell and the shell will then spawn a second process (for the echo command, in your case), so doubling the expense which was likely unacceptable in its single cost. –  mah Dec 3 '12 at 18:02
1 
@mah: Thanks for your explanation. While I admit my understanding wasn't perfect, I was trying to answer the part of the question where he asks if it was possible to print something without using printf, cout, or puts(). –  SidR Dec 3 '12 at 18:05 

No comments:

Post a Comment