MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Examples/Modules/Chapter 11/Ex11_03/Ex11_03.cpp:5–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import roman;
4
5int main()
6{
7 // std::string_view is reachable, so its constructor can be invoked
8 // (this constructor, unlike the std::string_view name itself, is visible)
9 std::cout << "MMXX in Arabic numerals is " << from_roman("MMXX") << std::endl;
10
11 // The names of the c_str() and size() members are visible as well
12 // (because the definition of std::string is reachable),
13 // and can thus be invoked.
14 std::cout << "1234 in Roman numerals is " << to_roman(1234).c_str() << std::endl;
15 std::cout << "This consists of " << to_roman(1234).size() << " numerals" << std::endl;
16
17 // std::string_view s{ "MMXX" }; /* Error: the name std::string_view is not visible */
18 // std::string roman{ to_roman(567) }; /* Error: the name std::string is not visible */
19
20 auto roman{ to_roman(567) };
21 std::cout << "567 in Roman numerals is " << roman.c_str() << std::endl;
22
23 // std::cout << "std::stoi() is not visible: " << std::stoi("1234") << std::endl;
24
25 // The << operator (which is implemented as a non-member function) is not visible either
26 // std::cout << "1234 in Roman numerals is " << to_roman(1234) << std::endl;
27}

Callers

nothing calls this directly

Calls 3

from_romanFunction · 0.70
to_romanFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected