[ create a new paste ] login | about

Link: http://codepad.org/qPy74LpC    [ raw code | output | fork ]

nadams - C++, pasted on Nov 27:
#include <iostream>
#include <sstream>

template <typename FROM, typename TO>
TO Convert(FROM obj)
{
    TO ret;
    std::stringstream s;
    s << obj;
    s >> ret;
    return ret;
}


int main()
{
    int x = Convert<const char *, int>("123");
    x++;
    cout << x << endl;
    std::string z = Convert<int, std::string>(x);
    z += "123";
    cout << z << endl;
}


Output:
1
2
124
124123


Create a new paste based on this one


Comments: