• Advertisement
Sign in to follow this  

StringStream headache

This topic is 4311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having trouble getting the extraction operator to work on my stringstreams. It works if and only if I use one insertion operator and then one extraction operator. When I put it in a loop to use it for multiple strings it just refuses to assign values with the extraction operator. I tried calling clear or flush or both on the stream but none of that works.
{        
    std::stringstream SS(std::stringstream::in | std::stringstream::out);
    std::string StrIn, Equals = "=", Dest;
    std::ifstream file(FileName.c_str());    

    Characters.clear();
    Characters.resize(255);
    for(int i = 0; i < 256; i++)
    {
        Characters = NULL;
    }    

    do
    {
        file >> StrIn;
    }while(StrIn != "common");

    do
    {
        file >> StrIn;        
        Split(StrIn, Equals,Dest);    
        SS.flush(); SS.clear();  
        SS << Dest;
        if(StrIn == "lineHeight")
        {
            SS >> lineHeight;
        }
    }while(StrIn != "char");

    do//while(StrIn != " kerning ");
    {
        Char* ch;
        if(StrIn == "char")
        {
            int ASCII, x, y, width, height, xoffset,yoffset,xadvance;
            do//while(StrIn != " char ");
            {
                if(StrIn == "id")
                    SS >> ASCII;   //These values aren’t being assigned.
                if(StrIn == "x")
                    SS >> x;    //These values aren’t being assigned.       
                if(StrIn == "y")
                    SS >> y;   //These values aren’t being assigned.
                if(StrIn == "width")
                    SS >> width;   //These values aren’t being assigned.
                if(StrIn == "height")
                    SS >> height;   //These values aren’t being assigned.
                if(StrIn == "xoffset")
                    SS >> xoffset;   //These values aren’t being assigned.
                if(StrIn == "yoffset")
                    SS >> yoffset;   //These values aren’t being assigned.
                if(StrIn == "xadvance")
                    SS >> xadvance;    //These values aren’t being assigned.
                file >> StrIn;        
                Split(StrIn, Equals,Dest);
                SS.flush(); SS.clear();  
                SS << "357"; //Dest;
            }while(StrIn != "char");
            //ch = new Char(
        }
        file >> StrIn;        
        Split(StrIn, Equals,Dest);
        SS.flush(); SS.clear();  
        SS << Dest;
    }while(StrIn != " kerning ");


Share this post


Link to post
Share on other sites
Advertisement
fail() is false;

str() appears to be every string I inserted one after the other. So it looks like its not being cleared out. What do I do?

Share this post


Link to post
Share on other sites
Quote:
Original post by Grain
So it looks like its not being cleared out. What do I do?


SS.str(""); to clear the string
SS.clear(); to clear the flags

Share this post


Link to post
Share on other sites
Excellent. Thanks.

Now why in the name of god doesn’t a regular string have convenient formatting operators like streams do?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement