Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <ranges>
- struct test {
- uint32_t ID;
- std::string name;
- struct point {
- double xx;
- double yy;
- double zz;
- } point;
- };
- struct testing {
- uint32_t ID;
- std::string name;
- struct point {
- double xx;
- double yy;
- double zz;
- } point;
- testing(uint32_t ID_ = 0u,
- std::string name_ = "",
- double xx_ = 0.0, double yy_ = 0.0, double zz_ = 0.0)
- : ID { ID_ }, name { name_ }, point { .xx = xx_, .yy = yy_, .zz = zz_ } {}
- };
- int main(int argc, char const * argv[]) {
- auto testpt = [](test const & tt) {
- std::cout << std::fixed << std::setprecision(3);
- std::cout << std::setw(3) << tt.ID
- << std::setw(15) << tt.name
- << std::setw(7) << tt.point.xx
- << std::setw(7) << tt.point.yy
- << std::setw(7) << tt.point.zz
- << '\n';
- };
- auto testingpt = [](testing const & tt) {
- std::cout << std::fixed << std::setprecision(3);
- std::cout << std::setw(3) << tt.ID
- << std::setw(15) << tt.name
- << std::setw(7) << tt.point.xx
- << std::setw(7) << tt.point.yy
- << std::setw(7) << tt.point.zz
- << '\n';
- };
- test t1 { 90u, "Test 90", { 8.4, 2.5, 9.9, } };
- testpt(t1);
- test t2 { .ID = 91u, .name = "Test 91", .point = { 7.3, 1.4, 8.8, } };
- testpt(t2);
- test t3 { .ID = 92u, .name = "Test 92", .point = { .xx = 6.1, .yy = 0.3, . zz = 7.7, } };
- testpt(t3);
- test t4 { 93u, "Test 03", 5.0, -0.2, 6.6, };
- testpt(t4);
- testing s0; // take defaults
- s0.name = "Testing 500";
- s0.point.yy = 11.02;
- testingpt(s0);
- testing s1(501u, "Testing 501", 11.1, 12.2, 13.3);
- testingpt(s1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement