🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #309988

Re: Piaskownica

#309988
From: herjohn
Date: Thu, 16 Jan 2020 12:01
131 lines
2853 bytes
W dniu 2019-12-12 o 23:54, M.M. pisze:
> Nie przewijajcie na dół, tam jest rozwiązanie:
> 
> Zawsze byłem słaby z biblioteki standardowej w C++, programowałem w innych.
> Nie mogłem znaleźć błędu w poniższych kilku wierszach, pewnie wy znajdziecie.
> Jako pierwszy wiersz na standardowe wejście podajemy liczby np. 1 i 2. Jako
> drugi podajemy np.: 3 i 4. Program dwa razy robi to samo, wczytuje wiersz,
> tworzy strumień tekstowy i ze strumienia odczytuje do zmiennych x i y. Choć
> dwa razy robi to samo, to drugi raz nie działa prawidłowo. Straciłem z
> godzinę czasu żeby to wygrzebać z większego programu, zdiagnozować i poprawić :)
> Biblioteki trzeba znać :/
> 
> #include <iostream>
> #include <sstream>
> 
> int main() {
>      std::string str;
>      std::istringstream ss;
>      double x, y;
> 
>      std::getline( std::cin , str );
>      std::cout << "String: '" << str << "'" << std::endl;
>      ss.str( str );
>      ss >> x >> y;
>      std::cout << x << std::endl;
>      std::cout << y << std::endl;
> 
>      std::getline( std::cin , str );
>      std::cout << "String: '" << str << "'" << std::endl;
>      ss.str( str );
>      ss >> x >> y;
>      std::cout << x << std::endl;
>      std::cout << y << std::endl;
> 
>      return 0;
> }
> 
> 
> Pozdrawiam
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------------------------------------------------
> Odpowiedź:
> 
> ss.str( str );
> nie resetuje pozycji, trzeba wywołać jeszcze:
> ss.seekg(0);
> 


a nie chodzi o to, że po pierwszej operacji
ss >> x >> y;
zostają ustawione bity eof, fail i bad, które trzeba wyzerować 
instrukcją ss.clear()?
Technical Details
Message-ID: <qvpja2$6vr$1@gioia.aioe.org>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.uzoreto.com!aioe.org!.POSTED.HFUrLSEMppKEAu89QDl92Q.user.gioia.aioe.org!not-for-mail
References: <4596f312-bb20-4ac0-ac42-015128f3dfdd@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.uzoreto.com!aioe.org!.POSTED.HFUrLSEMppKEAu89QDl92Q.user.gioia.aioe.org!not-for-mail
From: herjohn <herjohn@poczta.onet.pl>
Newsgroups: pl.comp.lang.c
Subject: Re: Piaskownica
Date: Thu, 16 Jan 2020 13:01:02 +0100
Organization: Aioe.org NNTP Server
Lines: 132
Message-ID: <qvpja2$6vr$1@gioia.aioe.org>
References: <4596f312-bb20-4ac0-ac42-015128f3dfdd@googlegroups.com>
NNTP-Posting-Host: HFUrLSEMppKEAu89QDl92Q.user.gioia.aioe.org
Mime-Version: 1.0
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit