Listing C
#include <string>
#include <sstream>
 
 
/////////////////////////////////////
// the 'to_string' function
template< class type>
inline std::string to_string( const type & value)
{
    std::ostringstream streamOut;
    streamOut << value;
    return streamOut.str();
}
 
 
 
 
 
 
 
 
 
 
int main()
{
    std::string strDocName = "doc_test.txt";
    int nWordsCount;
    // ... calculate words count
    nWordsCount = 48;
 
 
    // {1}
    // using to_string
    std::string str1 = "We have " + to_string( nWordsCount) + " words";
 
 
    // {2} "Emulating" to_string
    std::stringstream streamOut;
    streamOut << "We have " << nWordsCount << " words";
    std::string str2 = streamOut.str();
 
 
    return 0;
}