Jump to content
  • Advertisement
Sign in to follow this  
TEUTON

Difference between these two

This topic is 4435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is the difference between the two code and which should I use?
#include <iostream>
using namespace std;
int main() {
     char c;
     while ( cin.get(c) ) cout<<c;
} 

And 

#include <iostream>
using namespace std;
int main() {
     char c;
     while ( cin.get(c) ) cout.put(c);
} 

Share this post


Link to post
Share on other sites
Advertisement
[edit: whoops, not quite]Well, in this case they end up being exactly the same thing. In general, though, you should prefer the stream insertion operator (operator<<), as it performs formatted input (assuming this is what you want).


jfl.

Share this post


Link to post
Share on other sites
From MSDN:

cout.put() is said to put a character in the stream, and the overloaded << operator writes to the stream. Basically, cout.put() can only write a single character the the console, while cout<< will write an entire string; if you pass a string to cout.put(), you will get a compiler error.

EDIT: Beaten to it...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!