CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    I was constantly calling ostrstream? But private member access violation..

    Code:
    std::ostrstream oss;
    oss << "path for " << unit << "\n\t" << path;
    puts(oss.str());
    Code:
    class ostrstream
    	: public ostream
    	{	// output stream associated with a character array
    public:
    	typedef ostrstream _Myt;
    	typedef ostream _Mybase;
    	typedef strstreambuf _Mysb;
    
    	__CLR_OR_THIS_CALL ostrstream()
    		: ostream(&_Strbuffer), _Strbuffer()
    		{	// construct with empty character array
    		}
    
    	__CLR_OR_THIS_CALL ostrstream(char *_Ptr,
    		streamsize _Count,
    		ios_base::openmode _Mode =
    			ios_base::out)
    		: ostream(&_Strbuffer),
    			_Strbuffer(_Ptr, _Count,
    				_Ptr == 0 || (_Mode & ios_base::app) == 0
    					? _Ptr : _Ptr + _CSTD strlen(_Ptr))
    		{	// construct with [_Ptr, _Ptr + _Count)
    		}
    
    	__CLR_OR_THIS_CALL ostrstream(_Myt&& _Right)
    		: _Mybase(&_Strbuffer)
    		{	// construct by moving _Right
    		_Assign_rv(_STD forward<_Myt>(_Right));
    		}
    
    	_Myt& __CLR_OR_THIS_CALL operator=(_Myt&& _Right)
    		{	// move from _Right
    		_Assign_rv(_STD forward<_Myt>(_Right));
    		return (*this);
    		}
    
    	void __CLR_OR_THIS_CALL _Assign_rv(_Myt&& _Right)
    		{	// move from _Right
    		if (this != &_Right)
    			{	// different, swap base and buffer
    			_Strbuffer.clear();
    			this->swap(_Right);
    			}
    		}
    
    	void __CLR_OR_THIS_CALL swap(_Myt& _Right)
    		{	// swap with _Right
    		if (this != &_Right)
    			{	// different, swap base and buffer
    			_Mybase::swap(_Right);
    			_Strbuffer.swap(_Right._Strbuffer);
    			}
    		}
    
    	void __CLR_OR_THIS_CALL swap(_Myt&& _Right)
    		{	// swap with _Right
    		_Assign_rv(_STD forward<_Myt>(_Right));
    		}
    
    	virtual __CLR_OR_THIS_CALL ~ostrstream()
    		{	// destroy an ostrstream
    		}
    
    	_Mysb *__CLR_OR_THIS_CALL rdbuf() const
    		{	// return pointer to character array buffer
    		return ((_Mysb *)&_Strbuffer);
    		}
    
    	void __CLR_OR_THIS_CALL freeze(bool _Freezeit = true)
    		{	// freeze or unfreeze writing
    		_Strbuffer.freeze(_Freezeit);
    		}
    
    	char *__CLR_OR_THIS_CALL str()
    		{	// freeze and return pointer to character array
    		return (_Strbuffer.str());
    		}
    
    	streamsize __CLR_OR_THIS_CALL pcount() const
    		{	// return size of writable character array
    		return (_Strbuffer.pcount());
    		}
    
    private:
    	_Mysb _Strbuffer;	// the string buffer
    	};
    Today, I just received this new fresh error, I was constantly using them, but just come to know
    it is a private access violation as the last error of my program.
    Did I use it in the wrong way?
    Thanks
    Jack
    Last edited by lucky6969b; September 22nd, 2014 at 01:30 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: I was constantly calling ostrstream? But private member access violation..

    Is there a reason why you use the pre-standard ostrsream instead of std::ostringstream?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Dec 2010
    Posts
    907

    Re: I was constantly calling ostrstream? But private member access violation..

    Oh... is ostringstream better? thanks
    Let me try..

    Update:
    Same thing happening, I don't know where I touched it. But I just called oss.str(), oss.str().c_str(),
    and use it as a parameter of another function call.
    Thanks
    Jack
    Last edited by lucky6969b; September 22nd, 2014 at 02:19 AM.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: I was constantly calling ostrstream? But private member access violation..

    I am not sure about "better", but it is standard, available via <sstream>. ostrstream is pre-standard (though a check shows that it is actually listed as deprecated, but it has been deprecated since the start of standardisation).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured