GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


A Paste by Anonymous
1
 
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

///////////////////////////////////////////////////////////////////////

class MultiString {
    std::string str;
    static std::stringstream tempStrStream;
public:
    MultiString( std::string t ) : str(t) {}
    template< class T >
        T To() { 
            static T output;            
            tempStrStream.clear();
            tempStrStream.str( str );        
            tempStrStream >> output;
            return output;
        }
    template<>
        bool To() {
            return (str=="true"?true:false);
        }
};

std::stringstream MultiString::tempStrStream;

///////////////////////////////////////////////////////////////////////

int main() {
    MultiString test("100.43");
    MultiString test2("432.43");

    cout << test2.To<double>() << endl;
    cout << test.To<double>() << endl;
        
    cout << test.To<int>() << endl;
    cout << test2.To<int>() << endl;

    cout << test.To<float>() << endl;    
    cout << test2.To<float>() << endl;
    
}