manual on-line and Q

Angus Leeming a.leeming@ic.ac.uk
Tue Jun 25 04:21:00 GMT 2002


On Tuesday 25 June 2002 11:59 am, Martín Marqués wrote:
> I would like to know which is a good manual for not so newbie C/C++
> programmer (with info about math functions, etc.), and a Q I have.
>
> How do I concatenate into strings other data types, like double or int?

Try this GPL-ed code from the LyX project (www.lyx.org)
Angus

/// convert \a T to string
template<typename T>
inline
string const tostr(T const & t)
{
	ostringstream ostr;
	ostr << t;
	return ostr.str().c_str();
	// We need to use the .c_str since we sometimes are using
	// our own string class and that is not compatible with
	// basic_string<char>. (of course we don't want this later)
}


///
template<>
inline
string const tostr(bool const & b)
{
	return (b ? "true" : "false");
}

///
template<>
inline
string const tostr(string const & s)
{
	return s;
}



More information about the Gcc-help mailing list