]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lexical_cast/example/small_examples.cpp
ae9a88ea119b1a26a0e12845c1260288f77e258f
1 // Copyright 2013-2017 Antony Polukhin
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>.)
7 #include <boost/lexical_cast.hpp>
12 # pragma warning(disable: 4996) // `strerror` is not safe
15 //[lexical_cast_log_errno
16 //`The following example uses numeric data in a string expression:
18 void log_message(const std::string
&);
20 void log_errno(int yoko
)
22 log_message("Error " + boost::lexical_cast
<std::string
>(yoko
) + ": " + strerror(yoko
));
25 //] [/lexical_cast_log_errno]
28 //[lexical_cast_fixed_buffer
29 //`The following example converts some number and puts it to file:
31 void number_to_file(int number
, FILE* file
)
33 typedef boost::array
<char, 50> buf_t
; // You can use std::array if your compiler supports it
34 buf_t buffer
= boost::lexical_cast
<buf_t
>(number
); // No dynamic memory allocation
35 std::fputs(buffer
.begin(), file
);
38 //] [/lexical_cast_fixed_buffer]
40 //[lexical_cast_substring_conversion
41 //`The following example takes part of the string and converts it to `int`:
43 int convert_strings_part(const std::string
& s
, std::size_t pos
, std::size_t n
)
45 return boost::lexical_cast
<int>(s
.data() + pos
, n
);
48 //] [/lexical_cast_substring_conversion]
50 void log_message(const std::string
&) {}