[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] getchar buffer.



Hej Frederik

Et godt råd er at holde sig til C++-syntaks -- C++ er faktisk ikke så
ueffen som mange tror:
Nils_Åke_Ljunggren.in_avail();

håber at nedenstående kan hjælpe:

Frederik Treue skrev:

> Hej cprog
>
>     Jeg er stødt ind i et underligt problem der går som følger:

// BS 3. ed. page 621istream& eatwhite(istream& is){
    char c;
    while (is.get(c)) {
        if (!isspace(c)) {
            is.putback(c);
        }
    }
return is;
}

> ....
> ....
> void foo()
>   {
>   char str[10];
>   ...

// cin::operator >> (char* p) does not eat whitespace

>   cin >> str;

// Above is C++ -- se below

eatwhite(cin);

>   ....
>    }
>
> void main()
>    {

cin.sync_with_stdio(); // guarantees that C and C++ style I/O operations
share buffers

>    char ch='a';
>
>    do
>       {
>       foo();
>       ch=getchar();

/* above is C see above above*/

>       }
>    while (ch!='n')
>    }
>
> Det burde køre foo() indtil der tastes 'n' ved getchar() kaldet. Men,
> det virker som om det afsluttende '\n' fra cin i foo() "preller af", og
> bliver opfattet som input af getchar(). Hvorfor det ?!? Findes der en
> buffer for getchar(), og hvis ja: hvordan tømmer jeg den. Det skal lige

Der findes altid en sytembuffer (heldigvis)

> siges at jeg har modificeret getchar() således at den ikke venter på at
> man trykker enter, men tager input char for char, og her, kun tager en
> char og sender den videre.
>
> Regards
>     Frederik Treue





 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 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] *