[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] getline under en switch



Dennis Hansen <sslug@sslug> wrote:

>std::cin >> valg;

The extraction opererator does not remove any trailing whitespace!
Thus a trailing '\n' or sic. '\0' et al would still be pending.

*proper* eating of trailing whitespace is the answer to your overall 
question.

>         std::getline(std::cin,noget);

This is *not* std!

Det der sker er at din første extraction lader "whitespace" data blive i 
bufferen
derefter siger du til bufferen at du vil læse selv "whitespace"s - derfor 
modtager
du intet udover "whitespace" ved første læsning.

Dit problem er ikke nyt - der hvor det bliver sjovt er ved en tænkt 
istream: "\n\n\nHello\0\0\tWorld!"

Mvh
Nils Åke Ljunggren


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *