Advertisement
fcamuso

C++ 20 Lezione 3

Sep 25th, 2022
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <format>
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <chrono>
  7.  
  8. using namespace std;
  9.  
  10. double f() { return 123.456; }
  11.  
  12. class Cliente {
  13. private:
  14.     string ragioneSociale = "";
  15. public:
  16.     Cliente(string rs) { ragioneSociale = rs; }
  17.     string getRagioneSociale() const {return ragioneSociale;}
  18.  
  19. };
  20.  
  21. template <>
  22. struct std::formatter<Cliente> : std::formatter<std::string> {
  23.    
  24.     auto format(Cliente cli, format_context& ctx) {
  25.         return formatter<string>::format(
  26.             std::format("{}", "[[" + cli.getRagioneSociale()+"]]"), ctx);
  27.  
  28.     }
  29. };
  30.  
  31. int main()
  32. {
  33.     const string s1 = "primo placeholder";
  34.     const string s2 = "secondo placeholder";
  35.     const string s3 = "primo placeholder";
  36.     const string s5 = "PLACEHOLDER";
  37.     cout << "12345678901234567890\n";
  38.  
  39.     //for (int i = 1; i < 20; i++)
  40.         //cout << format("{0:10}{1:10} \n", i * i, i * i * i);
  41.         //cout << format("{0:#10x}{1:#10X} \n", i * i, i * i * i);
  42.         //cout << format("{0:#010x}{1:#10X}{2:*<10}\n", i * i, i * i * i, "ciao");
  43.  
  44.  
  45.     auto ora = chrono::system_clock::now();
  46.     cout << format("{:%d-%m-%Y %H:%M}\n", ora);
  47.  
  48.     ofstream file{ "dati.txt" };
  49.     format_to(ostream_iterator<char>(file), "prova, {}!", s3);
  50.     file.close();
  51.  
  52.     Cliente c1 =  Cliente("fcamuso incorporated");
  53.  
  54.     cout << format("{0:-^30}\n", c1);
  55.  
  56. }
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement