blob: edcc779244d38fe1e382f1101895aea9ffb18249 [file] [log] [blame]
Brian Silvermanf83c99f2018-08-04 23:36:58 -07001// Copyright 2013 Antony Polukhin
2
3// Distributed under the Boost Software License, Version 1.0.
4// (See the accompanying file LICENSE_1_0.txt
5// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
6
7//[lexical_cast_args_example
8//`The following example treats command line arguments as a sequence of numeric data
9
10#include <boost/lexical_cast.hpp>
11#include <vector>
12
13int main(int /*argc*/, char * argv[])
14{
15 using boost::lexical_cast;
16 using boost::bad_lexical_cast;
17
18 std::vector<short> args;
19
20 while (*++argv)
21 {
22 try
23 {
24 args.push_back(lexical_cast<short>(*argv));
25 }
26 catch(const bad_lexical_cast &)
27 {
28 args.push_back(0);
29 }
30 }
31
32 // ...
33}
34
35//] [/lexical_cast_args_example]