My code is as below
std::ostringstream tmpstr, tmpstr2;
for( /* something */ )
{
//writting inside tmpstr
}
tmpstr2 << tmpstr.rdbuf();
cout << "assigned to tmpstr2";
out <<tmpstr2.str().c_str() ; // Where out is ostrstream& out
This is last stack call in dump :-
std::basic_ostringstream<char,std::char_traits<char>,std::allocator<char> >::~basic_ostringstream
This last line when executed gives me a core dump . I am unable to understand the reason behind it . Can someone let me know if i am performing an operation that is invalid but is not a comilation error .
You have corrupted your memory with another statement. It’s hard to guess without seeing the actual code, but the best guess would be that you write out of bounds of something allocated before tmpstr or a stack-array directly afterwards.
either way, memory that should actually belong to the stream object is overwritten causing the stream object to break. The core dump happens after the actual broken line because it wasn’t detected. You wrote over some bounds but ended up in your program’s memory and not outside. In particular, in tmpstr’s memory.