Discussion: static istringstream
Afficher un message
Vieux 07/06/2008, 19h27   #5
Paavo Helde
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: static istringstream

sergey.lukoshkin@gmail.com kirjutas:

[...]
>
> Thanks a lot ! Now I call istr.clear() and it works properly.
> Here my fixed code.
>
> P.S I've never used boost lib.
>


You should, lots of it will be included in the next C++ standard.

>
> int main()
> {
> static std::string str;
> static std::istringstream istr;
> static unsigned val;


main() is called only once so the keyword 'static' does not change
anything here. Why do you think 'static' is needed?

And why do you define them here, not inside the loop where they are used?
Would have avoided all the trouble in the first place...

> while( true )
> {
> std::cout << "Enter num: " << std::endl;
> std::cin >> str;
>
> istr.clear();
> istr.str(str);
>
> istr >> val;
> std::cout << "Number: " << val << std::endl;
> }
>
> return 0;
>
> - Hide quoted text -
> - Show quoted text -
> }
>


Regards
Paavo
  Réponse avec citation
 
Page generated in 0,04605 seconds with 9 queries