x028.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xfmt.h"
4 #include <iostream>
5 #include <vector>
6 
7 namespace nmx::apps::x028 {
8 
12 inline void ex1() {
13  //Datentyp und Länge von std::array wird automatisch ermittelt
14  std::array x{ 1, 2, 3, 4, 5 }, y{ 6, 7, 8, 9, 10 };
15 
16  //Ausgabe-Funktion und Ausgabe
17  auto println = [](const auto &arg, const std::string &sep, const std::string &lend) {
18  std::cout << arg[0];
19  for (size_t idx = 1; idx < arg.size(); idx++) {
20  std::cout << sep << arg[idx];
21  }
22  std::cout << lend;
23  };
24  println(x, ", ", "\n");
25  println(y, " &", "\\\\\n");
26 }
27 
31 inline void ex2() {
32  Format fmt1{ "fmt1", ",\t", "\n", "dat" }, //
33  fmt2{ "fmt2", "&\t", "\\\\\n", "dat" };
34  std::array x{ 1, 2, 3, 4, 5 }, y{ 6, 7, 8, 9, 10 };
35  fmt1.set_defaults(std::cout); // es genügt ein Aufruf
36  fmt1.write_line(std::cout, x);
37  fmt2.write_line(std::cout, y);
38 }
39 
43 inline void ex3() {
44  Format fmt{ "fmt1", "\t", "\n", "dat" };
45  std::array x{ 1, 2, 3, 4, 5 }, y{ 6, 7, 8, 9, 10 };
46  fmt.set_defaults(std::cout);
47  fmt.as_rows(std::cout, x, y);
48 }
49 
53 inline void ex4() {
54  Format fmt{ "fmt1", ",\t", "\n", "csv" };
55  std::array x{ 1, 2, 3, 4, 5 }, //
56  y{ 6, 7, 8, 9, 10 }, //
57  z{ 11, 12, 13, 14, 15 };
58  fmt.set_defaults(std::cout);
59  fmt.as_columns(std::cout, x, y, z);
60 }
61 
65 inline void ex5() {
66  Format fmt{ "fmt1", ",\t", "\n", "csv" };
67  std::vector<std::vector<double>> table{ { 1, 2, 3, 4, 5 },
68  { 6, 7, 8, 9, 10 },
69  { 11, 12, 13, 14, 15 } };
70  fmt.set_defaults(std::cout);
71  fmt.as_columns(std::cout, table);
72 }
73 
74 } // namespace nmx::apps::x028
void ex1()
ex1 Beispiel für die formatierte Ausgabe von Arrays
Definition: x028.h:12
void ex5()
ex5 Beispiel für die formatierte Ausgabe eines Arrays
Definition: x028.h:65
void ex4()
ex4 Beispiel für die formatierte Ausgabe eines Arrays
Definition: x028.h:53
void set_defaults(std::ostream &ofs) const
set_defaults Formatierung der Zahlen
Definition: xfmt.h:133
The Format class Formatierte Ausgabe von Arrays.
Definition: xfmt.h:10
void ex2()
ex2 Beispiel für die formatierte Ausgabe eines Arrays
Definition: x028.h:31
void ex3()
ex3 Beispiel für die formatierte Ausgabe eines Arrays
Definition: x028.h:43