C
Christopher Benson-Manica
This is a subtle variation of a question I posted some time ago.
#include <map>
#include <iostream>
#include <sstream>
int main(void)
{
try {
std::stringstream s;
std::cout << "s=" << s.str() << "\n";
s << "Hello, world!\n";
std::cout << "s=" << s.str();
s.str().erase();
std::cout << "s=" << s.str();
s.str( "" );
std::cout << "s=" << s.str() << std::endl;
return 0;
}
catch( const std::exception &e ) {
std::cerr << "Exception catch: " << e.what() << std::endl;
}
return 0;
}
When compiled with my broken implementation, I get the following output:
s=
s=Hello, world!
s=Hello, world!
Exception catch: unexpected NULL pointer in function: basic_string( const charT* ,size_type,const Allocator&)
Is there any way to coerce my God-forsaken implementation to actually
clear the stringstream? Or will I have to use a stringstream* and
create a new one when I want a clean one?
#include <map>
#include <iostream>
#include <sstream>
int main(void)
{
try {
std::stringstream s;
std::cout << "s=" << s.str() << "\n";
s << "Hello, world!\n";
std::cout << "s=" << s.str();
s.str().erase();
std::cout << "s=" << s.str();
s.str( "" );
std::cout << "s=" << s.str() << std::endl;
return 0;
}
catch( const std::exception &e ) {
std::cerr << "Exception catch: " << e.what() << std::endl;
}
return 0;
}
When compiled with my broken implementation, I get the following output:
s=
s=Hello, world!
s=Hello, world!
Exception catch: unexpected NULL pointer in function: basic_string( const charT* ,size_type,const Allocator&)
Is there any way to coerce my God-forsaken implementation to actually
clear the stringstream? Or will I have to use a stringstream* and
create a new one when I want a clean one?