[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



Hej

Jeg havde et lignende problem engang.. Det var vist noget med at der bliver 
efterladt et \n i streamen nogengange.. Prøv at flushe streamen inden du 
kalder getline.

/Troels

On Wednesday 30 May 2001 20:47, you wrote:
> Hej,
> Jer er ved at lave et lille C++ program.
> Jeg bruger gcc 2.96 under Mandrake 8.0
>
> getline opfører sig mystisk hvis jeg bruger den under en switch / case,
> så er jeg nød til at kalde den to gange ellers virker det som om den bare
> ignorerer det første kald.
>
> Jeg har kun oplevet dette hvis den bliver kaldt inde i en swich, udenfor
> virker det som jeg ville forvente.
>
> Her er en stump kode som viser problemet.
>
>
> //------------------------------------
> #include <string>
> #include <iostream>
> int main()
> {
>    char valg;
>    std::string noget;
>
>    std::cout << "Indtast valg : ";
>    std::cin >> valg;
>    switch (valg)
>    {
>       case '1':
>          std::cout << "Indtast noget : ";
>          std::getline(std::cin,noget);
>
>          // nød til at insætte en ekstra getline her
>          std::getline(std::cin,noget);
>          std::cout << "Du tastede " << noget << std::endl;
>          break;
>
>       default:
>          break;
>    }
>    return 0;
> }
> //-------------------------------------
>
> Hvorfor skal den have den to gange for at virke ?
>
> Mvh
>
> Dennis

-- 
Med venlig hilsen
Troels Anders Dam Nissen


------------------------------------------
                            FrontCraft I/S 
------------------------------------------
http://www.FrontCraft.dk    
sslug@sslug 
------------------------------------------
Programudvikling og konsulentarbejde
------------------------------------------


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