[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



In article <sslug@sslug> you wrote:


>>    char dummy;
>>    std::cout << "Indtast valg : " << flush;
>>    std::cin >> valg;
>>    std::cin >> dummy; // læs LF, i DOS CR-LF ?
>>  ....
>> 

> Tak jeg kan godt se problemet.
> Jeg er først lige startet på at programmere under linux, og har aldrig haft 
> dette problem under Windows.

Men hvordan har du indlæst i Windows ?, med windows/DOS getchar() ?

> Det er fra en consol, hvordan læser jeg automatisk LF ind i den dummy ?

Det er vist ovendofr (dummy), men løsningen er uegnet da hvad
hvis der ikke er LF ?

Nu ved jeg jo ikke i hvilken sammenhæng programmet skal virke.

Skal det virke med både consol og redirected input, vil jeg foreslå
at du indlæser HELE linier i en liniebuffer i stedet for tegn/linier
blandet.
Så skal du blot fiske "valg" ud af strengen liniebuffer.

Vil du have noget der skal virke uden at trykke "ENTER" efter hver input
så plejer jeg i C at kalde

  tcsetattr ( fd, TCSAFLUSH, &saved_termios_data );

(og passende kald til at sætte indstillinger korrekt når programmet slutter)

Dettte virker dog ikke helt godt med blandet C++ std::cin, men det
virker med getch() og andre standard C input kald.

Alternativ brug ncurses (også C) til konsol/xterm....

Readline() var også en måde hvis man vil have redigeringsmuligheder.


-- 
Frank Damgaard 



 
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] *