diff between cout and puts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cuteanu
    New Member
    • Oct 2006
    • 14

    diff between cout and puts

    Please someone could guide me with the difference between cin,gets,getlin e and cout,puts,write .Especially cout and puts gives the same output then how are they different?????
  • dariophoenix
    New Member
    • Oct 2006
    • 34

    #2
    Originally posted by cuteanu
    Please someone could guide me with the difference between cin,gets,getlin e and cout,puts,write .Especially cout and puts gives the same output then how are they different?????

    1 - puts is an ANSI C function defined in the <stdio.h> header
    2 - cout is not a function: it's a stream, associated to a file. When you do something like:
    cout << "Hello" << endl;
    You are using operator << (operator 'send to', which is a function, but written in C++, so unlike puts, it's Object-Oriented) : you are sending the string "Hello" to the stream cout, which is analogous to C's stdout.
    3 - Same for getline and cin, except that getline is redefined in C++'s <iostream> header, so you need to be careful.

    If you need to do basic I/O in C++, check this site, I found it very useful:

    www.cppreferenc e.com

    Comment

    Working...