#include <iostream>
#include <iomanip> // needed for std::setw()
#include "string_format.h"

int main()
{
    {
        std::string input = "1234.56789";
        double value;
        if ( string2type( input, value, std::fixed ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::fixed << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::fixed ); // 1234.567890
            std::cout << "\tstd::fixed";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "1234.56789";
        double value;
        if ( string2type( input, value, std::fixed ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::fixed << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::fixed, 3 ); // 1234.568
            std::cout << "\tstd::fixed + precision == 3";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "56e2";
        double value;
        if ( string2type( input, value ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value ); // 5600
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "56e+2";
        double value;
        if ( string2type( input, value, std::showpoint ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::showpoint << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::showpoint ); // 5600
            std::cout << "\tstd::showpoint";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "234.5678";
        double value;
        if ( string2type( input, value, std::scientific ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::scientific << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::scientific ); // 1.234568e+003
            std::cout << "\tstd::scientific";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "255";
        int value;
        if ( string2type( input, value ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value ); // 255
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "FF"; // or 0xFF
        int value;
        if ( string2type( input, value, std::hex ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::hex << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::hex ); // ff
            std::cout << "\tstd::hex";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "777"; // or 0777
        int value;
        if ( string2type( input, value, std::oct ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::oct << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::oct ); // 777
            std::cout << "\tstd::oct";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "true"; // or false
        bool value;
        if ( string2type( input, value, std::boolalpha ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << std::boolalpha << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value, std::boolalpha ); // true
            std::cout << "\tstd::boolalpha";
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';
    {
        std::string input = "1"; // or 0
        bool value;
        if ( string2type( input, value ) ) {
            std::cout << std::setw( 12 ) << input << '\t';
            std::cout << std::setw( 12 ) << value << '\t';
            std::cout << std::setw( 12 ) << type2string( value ); // 1
        } else {
            std::cout << "BAD input: " << input;
        }
    }
    std::cout << '\n';

    return 0;
}

/*
Output:
  1234.56789     1234.567890     1234.567890    std::fixed
  1234.56789     1234.567890        1234.568    std::fixed + precision == 3
        56e2     5600.000000            5600
       56e+2     5600.000000         5600.00    std::showpoint
    234.5678    2.345678e+002   2.345678e+002   std::scientific
         255             255             255
          FF              ff              ff    std::hex
         777             777             777    std::oct
        true            true            true    std::boolalpha
           1            true               1
*/