C++ Library Extensions 2022.12.09
To help learn modern C++ programming
002-conversion.cpp
Go to the documentation of this file.
1
12#include <tpf_conversion.hpp>
13#include <tpf_output.hpp>
14#include <vector>
15
22{
23 using namespace tpf::conversion;
24
25 // load default system locale
27
28 // converts wchar_t to char
29 std::cout << "From UTF16 wchar_t to UTF8 char: "
30 << utf16_to_utf8(L'A') << std::endl;
31
32 // converts char to wchar_t
33 std::wcout << L"From UTF8 char to UTF16 wchar_t: "
34 << utf8_to_utf16('A') << std::endl;
35
36 // converts UTF16 wchar_t* to std::string
37 std::cout << "From UTF16 wchar_t* to UTF8 std::string: ["
38 << utf16_to_utf8(L"Korean") << "]"<< std::endl;
39
40 // converts UTF8 char to UTF16 std::wstring
41 std::wcout << L"From UTF8 char* to UTF16 std::wstring: ["
42 << utf8_to_utf16("char literal string") << L"]"<< std::endl;
43
44 std::string utf8str("I don't know");
45
46 // converts UTF8 std::string to UTF16 std::wstring
47 std::wcout << L"From UTF8 std::string to UTF16 std::wstring ["
48 << utf8_to_utf16(utf8str) << L"]" <<std::endl;
49
50 std::wstring utf16str(L"UTF16 string");
51
52 // converts UTF16 std::wstring to UTF8 std::string
53 std::cout << "From UTF16 std::wstring to UTF8 std::string ["
54 << utf16_to_utf8(utf16str) << "]" <<std::endl;
55}
56
61{
62 using namespace tpf::conversion;
63
64 // load default system locale
66
67 tpf::ostream stream;
68
69 stream.std() << std::boolalpha;
70
71 stream << L"김창희" << " 사랑해요... " << true ;
72
73 using typelist_t = tpf::types::type_list_t<int, double>;
74
75 auto nl = "\n";
76
77 stream << " - types: "<< typelist_t{} << nl;
78
79}
80
82{
83 using namespace tpf::conversion;
84
85 // load default system locale
87 auto nl = "\n";
88
89 tpf::ostream stream;
90
91 stream << std::string("김창희");
92
93 stream << std::wstring(L" 뭔데요?") << nl;
94}
95
97{
98 using namespace tpf::conversion;
99 auto nl = "\n";
100
101 // load default system locale
103
104 tpf::ostream stream;
105
106 std::vector<int> v{1, 2, 3, 4, 5};
107
108 stream << v << " - 사랑해요, 김창희..." << nl;
109
110}
111
112int main()
113{
114 test_output();
115 // test_string_output();
116 // test_container_output();
117
118}
void test_output()
void test_container_output()
void examples_string_conversion()
String encoding conversion examples.
void test_string_output()
int main()
auto nl
auto & cout
auto & endl
tpf::sstream stream
void load_default_locale(bool ShowLocaleName=false)
Load system default locale for string conversion.
std::wstring utf8_to_utf16(const std::string &utf8str)
Converts UTF8 std::string to UTF16 std::wstring.
std::string utf16_to_utf8(const std::wstring &utf16str)
Converts UTF16 std::wstring to UTF8 std::string.
String conversions are implemented.
This type is used to manipulate type list.
Definition: tpf_types.hpp:956
String conversions are implemented.
Stream output operators << are implemented.