By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

diff between cout and puts

P: 14
Please someone could guide me with the difference between cin,gets,getline and cout,puts,write.Especially cout and puts gives the same output then how are they different?????
Nov 6 '06 #1
Share this Question
Share on Google+
1 Reply


P: 34
Please someone could guide me with the difference between cin,gets,getline 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.cppreference.com
Nov 6 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.