osh.h

My personal stdc++ replacement
git clone git://git.oshgnacknak.de/osh.h.git
Log | Files | Refs | README

print.cpp (2188B)


      1 #include "osh.h"
      2 
      3 using namespace osh;
      4 
      5 struct Vector2 {
      6     double x, y;
      7 };
      8 
      9 void print1(Formatter auto& fmt, Vector2& v) {
     10     printp(fmt, "Vector2(", v.x, ", ", v.y, ')');
     11 }
     12 
     13 int main() {
     14     print("Hallo, Welt -");
     15     println(" Hello, World!");
     16     
     17     println("Concatinating different data types:",
     18         '-', 5, 6.0d, 9, '+', 'L');
     19 
     20     char c = 'A';
     21     println("Printing char: ", c);
     22 
     23     int i = 69;
     24     println("Printing int: ", i);
     25         
     26     short int si = 420;
     27     println("Printing short int: ", si);
     28         
     29     long int li = 666;
     30     println("Printing long int: ", li);
     31         
     32     long long int lli = 0xdeadbeef;
     33     println("Printing long long int: ", lli);
     34 
     35     unsigned char uc = 'E';
     36     println("Printing unsigned char: ", uc);
     37     
     38     unsigned int ui = 1337;
     39     println("Printing unsigned int: ", ui);
     40     
     41     unsigned short int usi = 25565;
     42     println("Printing unsigned short int: ", usi);
     43     
     44     unsigned long int uli = 0xadbdef;
     45     println("Printing unsigned long int: ", uli);
     46     
     47     unsigned long long int ulli = 987665543210;
     48     println("Printing unsigned long long int: ", ulli);
     49         
     50     float f = 3.141592653589793;
     51     println("Printing float: ", f);
     52         
     53     double d = 2.71828;
     54     println("Printing double: ", d);
     55 
     56     long double ld = 1.141592653589793;
     57     println("Printing long double: ", ld);
     58 
     59     println("Printing a pointer to anythink (excluding char*): ",
     60         &i, ", ",
     61         &si, ", ",
     62         &li, ", ",
     63         &lli, ", ",
     64         &f, ", ",
     65         &d, ", ",
     66         &ld);
     67 
     68     char buf[32];
     69     buf[0] = 'b';
     70     buf[1] = 'u';
     71     buf[2] = 'f';
     72     buf[3] = 'f';
     73     buf[4] = 'e';
     74     buf[5] = 'r';
     75     buf[6] = '\0';
     76     println("Printing char buffers: ", buf);
     77 
     78     Vector2 v = { 69, 420 };
     79     println("Printing costume types (see print1 above): ", v);
     80     println("^ Comment it out, error message is ACTUALLY readable");
     81 
     82     eprint("Printing to stderr: ", "you error is soos ", d, f);
     83     eprintln(" and here some saas");
     84 
     85     FileFormatter fmt(stderr);
     86     printp(fmt, "Printing to any FILE* other than stdout: ", buf, " - ", v, '\n');
     87 
     88     return 0;
     89 }
     90 
     91 #define OSH_H_IMPLEMENTATION
     92 #include "osh.h"