   More streamproblems...
  Question 1:If a stream operation fails, it will set the fail bit, which you can check with fail(). Now, how do you clear this fail bit?Question 2:Somehow this doesnt work:m_String.str("");m_String << (*m_pVariable);Where m_String is an std::stringstream and m_pVariable is a valid pointer to an unsigned int variable... I just don''t get it, it should be working fine, but when I get the m_String.str(), the string is still empty...   Looking for a serious game project?www.xgameproject.com
  1) basic_ios::clear(). Just remember the bit you want to clear.2) Works fine for me. Are all the error flags clear on the string before you do the insertion? ;  Yes its all clear... Its very strange, works fine out of my program, but when I actually do it, it doesnt work... Some external factor must be affecting this.   Looking for a serious game project?www.xgameproject.com;quote:Original post by Max_Payne  Some external factor must be affecting this. Did you remember to compensate for the phase of the moon and the state of the stock market ?   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);quote:Original post by Fruny  quote:Original post by Max_Payne   Some external factor must be affecting this. Did you remember to compensate for the phase of the moon and the state of the stock market ?   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor) How could I forget that...   Looking for a serious game project?www.xgameproject.com;  You fool! Phase of the moon doesn''t matter. Now which house Mercury is in during compiles - that matters. More seriously, there could be a buffer overrun or something going on with your std::stringstream that''s setting the internal rdbuf pointer to null. That will usually cause insertion or extraction operators to fail without actually crashing your program. ;  I don''t know how it could set the rdbuf pointer to NULL.Anyhow, I was able to re-create an error: std::stringstream String;unsigned int Integer = 3;String.str("moocow");String >> Integer;if (String.fail())std::cout << "Failed" << std::endl;std::cout << String.str() << std::endl;String.clear(std::ios_base::failbit);String.str("");String << Integer;std::cout << String.str() << std::endl;if (String.fail())std::cout << "Failed" << std::endl;The previous code outputs:FailedmoocowFailedThe first input operation fails on purpose. I then try to clear the fail bit and perform an input operation, but it doesnt work and reports that it failed...   Looking for a serious game project?www.xgameproject.com;quote:String.clear(std::ios_base::failbit);This is not so good. String.clear() should be fine for what you''re doing.;quote:Original post by SiCrane   quote:String.clear(std::ios_base::failbit);This is not so good. String.clear() should be fine for what you're doing.Yes, String.clear() works.... But my code still screws up... I'll post code, hopefully this will help: // Function to set the variablebool SetVariable(const std::string& String){ // Set the variablem_String.str(String); m_String >> (*m_pVariable); // If the variable setting failedif (m_String.fail()){// Clear the fail bitm_String.clear();// Return an errorreturn false;}// Variable setreturn true;}// Function to get the variablestd::string GetVariable(){// Reset the variable stringm_String.str("");m_String << (*m_pVariable);// Return the variable stringreturn m_String.str();}In this case:- m_String is an std::stringstream- m_pVariable is a valid pointer to an unsigned int.I call both SetVariable() and GetVariable() a few times. The second time I call SetVariable(), it returns false... And GetVariable() always returns ""...   Using VC++ 6 standard.Looking for a serious game project?  www.xgameproject.com [edited by - Max_Payne on February 2, 2004 12:09:11 AM];  What arguments are you using for SetVariable()?And have you considered just using boost::lexical_cast instead? 