| Home | Libraries | People | FAQ | More

## Examples

The following example treats command line arguments as a sequence of numeric data:

    int main(int argc, char * argv[])
    {
        using boost::lexical_cast;
        using boost::bad_lexical_cast;

        std::vector<short> args;

        while(*++argv)
        {
            try
            {
                args.push_back(lexical_cast<short>(*argv));
            }
            catch(bad_lexical_cast &)
            {
                args.push_back(0);
            }
        }
        ...
    }

The following example uses numeric data in a string expression:

    void log_message(const std::string &);

    void log_errno(int yoko)
    {
        log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));
    }