getchar vs. cin

K

Kristo

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
 
T

Thomas Matthews

Kristo said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top