Link to home
Start Free TrialLog 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
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial