Link to home
Create AccountLog in
Avatar of perlperl
perlperl

asked on

stringstream

What is the use of stringstream to return string in this format.  I see at most places in my application
std::string  SID::to_string() const 
{
	std::stringstream short_sid_stream;
	short_sid_stream << _in << "-" << _out;
	return short_sid_stream.str();
}

Open in new window


I am not sure why didn't the original developer wrote something like this.
std::string  SID::to_string() const 
{
	std::string short_sid (_in);
        short_sid += "-"; 
        short_sid += _out;
	return short_sid();
}

Open in new window


Is there any specific benefit of method 1 over method 2 except saving 1 line ?
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer