Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > getchar vs. cin

Reply
Thread Tools

getchar vs. cin

 
 
Kristo
Guest
Posts: n/a
 
      03-23-2005
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

 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      03-24-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using cin.get() and cin.eof() ends up in an endless loop Fernando C++ 4 11-16-2011 07:19 PM
cin and cin.getline() Aleander C++ 5 03-06-2005 03:57 PM
Use of getchar Cam C++ 3 05-30-2004 11:39 AM
std::cin.ignore() and std::cin.clear() Chris Mantoulidis C++ 5 01-06-2004 11:08 PM
cin and cin.clear() problem TaiwanNoWhere C++ 8 10-17-2003 05:53 PM



Advertisments