]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/lexical_cast/example/small_examples.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / lexical_cast / example / small_examples.cpp
CommitLineData
7c673cae
FG
1// 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#include <boost/lexical_cast.hpp>
8#include <string>
9#include <cstdio>
10
11//[lexical_cast_log_errno
12//`The following example uses numeric data in a string expression:
13
14void log_message(const std::string &);
15
16void log_errno(int yoko)
17{
18 log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));
19}
20
21//] [/lexical_cast_log_errno]
22
23
24//[lexical_cast_fixed_buffer
25//`The following example converts some number and puts it to file:
26
27void number_to_file(int number, FILE* file)
28{
29 typedef boost::array<char, 50> buf_t; // You can use std::array if your compiler supports it
30 buf_t buffer = boost::lexical_cast<buf_t>(number); // No dynamic memory allocation
31 std::fputs(buffer.begin(), file);
32}
33
34//] [/lexical_cast_fixed_buffer]
35
36//[lexical_cast_substring_conversion
37//`The following example takes part of the string and converts it to `int`:
38
39int convert_strings_part(const std::string& s, std::size_t pos, std::size_t n)
40{
41 return boost::lexical_cast<int>(s.data() + pos, n);
42}
43
44//] [/lexical_cast_substring_conversion]
45
46void log_message(const std::string &) {}
47
48int main()
49{
50 return 0;
51}
52