-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path08-format2.cpp
31 lines (26 loc) · 864 Bytes
/
08-format2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 08-format2.cpp : Various format string-using functions
#include <print>
#include <format>
#include <string>
#include <iostream>
#include <iterator>
#include <array>
#include <cmath>
using namespace std;
int main() {
string world{ "World" };
print(cout, "Hello, {}!\n", world);
println("{1} or {0}", false, true);
constexpr const char *fmt = "Approximation of π = {:.12g}";
string s = format(fmt, asin(1.0) * 2);
cout << s << '\n';
constexpr const wchar_t *wfmt = L"Approximation of pi = {:.12g}";
wstring ws = format(wfmt, asin(1.0) * 2);
wcout << ws << L'\n';
format_to(ostream_iterator<char>(cout), "Hello, {}!\n", world);
wstring ww{ L"World" };
array<wchar_t,9> wa;
auto iter = format_to_n(wa.begin(), 8, L"Hello, {}!\n", ww);
*(iter.out) = L'\0';
wcout << wa.data() << L'\n';
}