[LC++]Stringstream problems

Carlo Wood carlo at alinoe.com
Sat Nov 30 19:58:01 UTC 2002


On Fri, Nov 29, 2002 at 07:20:08PM -0800, Charles Randle wrote:
> Hi All,
> 
> 1) Can someone please explain why the code snippet
> below sets the fail bit after executing the statement
> before the if test ??
> #include <sstream>
> #include <iostream>
> 
> 
> int main() {
>   ::std::stringstream grubbyStream;
>   ::std::string cfgString= "CONFIGSTRING {";
>   ::std::string blockName;
>   ::std::string dummyString;
> 
>     // Set up stream 
>     grubbyStream.str("");
>     grubbyStream << cfgString;
>     grubbyStream >> blockName;
>     grubbyStream >> dummyString;
> 
>     grubbyStream << "WHAT HAPPENE";
>     if (grubbyStream.fail()) ::std::cerr << "WE ARE
> DEAD !!";
> }

~>g++-2.95.2 troep.cc; a.out
troep.cc:1: sstream: No such file or directory
~>g++-2.95.3 troep.cc; a.out
~>g++-2.96 troep.cc; a.out
WE ARE DEAD !!
~>g++-3.0.4 troep.cc; a.out
~>g++-3.1 troep.cc; a.out
~>g++-3.2 troep.cc; a.out

Upgrade your compiler.

> 2) What exactly is the use of the stream function "
> ::std::ends "

It add a '\0' to the std::string.

-- 
Carlo Wood <carlo at alinoe.com>



More information about the tuxCPProgramming mailing list