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

getchar vs. cin

P: n/a
Is there a preference between getchar and cin for reading one character
at a time from stdin? TC++PL chapter 6 has a parser that uses getchar,
but I suspect that the purists will say to always go with cin.
Naturally, the former is probably faster. However, in the context of
writing a parser, I think istream's skipws and noskipws manipulators
could be useful. Opinions?

Kristo

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Kristo wrote:
Is there a preference between getchar and cin for reading one character
at a time from stdin? TC++PL chapter 6 has a parser that uses getchar,
but I suspect that the purists will say to always go with cin.
Naturally, the former is probably faster. However, in the context of
writing a parser, I think istream's skipws and noskipws manipulators
could be useful. Opinions?

Kristo


All depends on the features you want in your
stream handler.

The C++ streams have better exception handling
than the C versions; however, the C versions have
less overhead than the C++ streams.

The C++ streams are more adaptable to different
situations than the C streams.

You would need more information about the I/O
to make a good decision. On some platforms, you
may be using O.S. functionality rather than
the C++ streams.

Text applications have different requirements than
windowing, I/O to devices, or file I/O.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.