| [53ba273] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
|  | 7 | // io.c -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Peter A. Buhr | 
|---|
|  | 10 | // Created On       : Wed Mar  2 16:56:02 2016 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [5a7966bb] | 12 | // Last Modified On : Thu Jun  8 09:52:10 2017 | 
|---|
|  | 13 | // Update Count     : 51 | 
|---|
| [53ba273] | 14 | // | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include <fstream> | 
|---|
|  | 17 |  | 
|---|
|  | 18 | int main() { | 
|---|
| [5a7966bb] | 19 | char c;                                                                                         // basic types | 
|---|
| [53ba273] | 20 | short int si; | 
|---|
|  | 21 | unsigned short int usi; | 
|---|
|  | 22 | int i; | 
|---|
|  | 23 | unsigned int ui; | 
|---|
|  | 24 | long int li; | 
|---|
|  | 25 | unsigned long int uli; | 
|---|
|  | 26 | long long int lli; | 
|---|
|  | 27 | unsigned long long int ulli; | 
|---|
|  | 28 | float f; | 
|---|
|  | 29 | double d; | 
|---|
|  | 30 | long double ld; | 
|---|
|  | 31 | float _Complex fc; | 
|---|
|  | 32 | double _Complex dc; | 
|---|
|  | 33 | long double _Complex ldc; | 
|---|
| [5a7966bb] | 34 | enum { size = 10 }; | 
|---|
|  | 35 | char s1[size], s2[size]; | 
|---|
| [53ba273] | 36 |  | 
|---|
| [58b5d03] | 37 | int x = 3, y = 5, z = 7; | 
|---|
|  | 38 | sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; | 
|---|
|  | 39 | sout | 1 | 2 | 3 | endl; | 
|---|
|  | 40 | sout | '1' | '2' | '3' | endl; | 
|---|
|  | 41 | sout | 1 | "" | 2 | "" | 3 | endl; | 
|---|
|  | 42 | sout | endl; | 
|---|
|  | 43 |  | 
|---|
| [5a7966bb] | 44 | sout | 
|---|
|  | 45 | // opening delimiters | 
|---|
|  | 46 | | "x (" | 1 | 
|---|
|  | 47 | | "x [" | 2 | 
|---|
|  | 48 | | "x {" | 3 | 
|---|
|  | 49 | | "x =" | 4 | 
|---|
|  | 50 | | "x $" | 5 | 
|---|
|  | 51 | | "x £" | 6 | 
|---|
|  | 52 | | "x ¥" | 7 | 
|---|
|  | 53 | | "x ¡" | 8 | 
|---|
|  | 54 | | "x ¿" | 9 | 
|---|
|  | 55 | | "x «" | 10 | 
|---|
|  | 56 | | endl; | 
|---|
|  | 57 | sout | 
|---|
|  | 58 | // closing delimiters | 
|---|
|  | 59 | | 1 | ", x" | 
|---|
|  | 60 | | 2 | ". x" | 
|---|
|  | 61 | | 3 | "; x" | 
|---|
|  | 62 | | 4 | "! x" | 
|---|
|  | 63 | | 5 | "? x" | 
|---|
|  | 64 | | 6 | "% x" | 
|---|
|  | 65 | | 7 | "¢ x" | 
|---|
|  | 66 | | 8 | "» x" | 
|---|
|  | 67 | | 9 | ") x" | 
|---|
|  | 68 | | 10 | "] x" | 
|---|
|  | 69 | | 11 | "} x" | 
|---|
|  | 70 | | endl; | 
|---|
|  | 71 | sout | 
|---|
|  | 72 | // opening-closing delimiters | 
|---|
|  | 73 | | "x`" | 1 | "`x'" | 2 | 
|---|
|  | 74 | | "'x\"" | 3 | "\"x:" | 4 | 
|---|
|  | 75 | | ":x " | 5 | " x\t" | 6 | 
|---|
|  | 76 | | "\tx\f" | 7 | "\fx\v" | 8 | 
|---|
|  | 77 | | "\vx\n" | 9 | "\nx\r" | 10 | 
|---|
|  | 78 | | "\rx" | | 
|---|
|  | 79 | endl; | 
|---|
|  | 80 | sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; | 
|---|
|  | 81 |  | 
|---|
|  | 82 | ifstream in;                                                                            // create / open file | 
|---|
| [6b6597c] | 83 | open( &in, "io.data", "r" ); | 
|---|
| [53ba273] | 84 |  | 
|---|
| [5a7966bb] | 85 | &in | &c                                                                                        // character | 
|---|
|  | 86 | | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli     // integral | 
|---|
|  | 87 | | &f | &d | &ld                                                                 // floating point | 
|---|
|  | 88 | | &fc | &dc | &ldc                                                              // floating-point complex | 
|---|
|  | 89 | | cstr( s1 ) | cstr( s2, size );                                // C string, length unchecked and checked | 
|---|
| [53ba273] | 90 |  | 
|---|
| [5a7966bb] | 91 | sout | c | ' ' | endl                                                           // character | 
|---|
|  | 92 | | si | usi | i | ui | li | uli | lli | ulli | endl // integral | 
|---|
|  | 93 | | f | d | ld | endl                                                             // floating point | 
|---|
|  | 94 | | fc | dc | ldc | endl;                                                 // complex | 
|---|
| [53ba273] | 95 | sout | endl; | 
|---|
| [5a7966bb] | 96 | sout | f | "" | d | "" | ld | endl                                      // floating point without separator | 
|---|
|  | 97 | | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator | 
|---|
|  | 98 | | sepOn | s1 | sepOff | s2 | endl                               // local separator removal | 
|---|
|  | 99 | | s1 | "" | s2 | endl;                                                  // C string without separator | 
|---|
| [53ba273] | 100 | sout | endl; | 
|---|
|  | 101 |  | 
|---|
| [5a7966bb] | 102 | sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters | 
|---|
| [829c907] | 103 | sout | f | d | ld | endl | 
|---|
| [5a7966bb] | 104 | | fc | dc | ldc | endl | 
|---|
|  | 105 | | s1 | s2 | endl; | 
|---|
| [6b6597c] | 106 | sout | endl; | 
|---|
| [5a7966bb] | 107 |  | 
|---|
|  | 108 | [int, int] t1 = [1, 2], t2 = [3, 4]; | 
|---|
|  | 109 | sout | t1 | t2 | endl;                                                          // print tuple | 
|---|
|  | 110 |  | 
|---|
| [6b6597c] | 111 | sepSet( sout, " " ); | 
|---|
| [5a7966bb] | 112 | sepSet( sout, ", $" );                                                          // set separator from " " to ", $" | 
|---|
|  | 113 | sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; | 
|---|
|  | 114 | sepSet( sout, " " );                                                            // reset separator to " " | 
|---|
|  | 115 | sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; | 
|---|
| [6b6597c] | 116 |  | 
|---|
| [5a7966bb] | 117 | sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // separator at start of line | 
|---|
|  | 118 | sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator | 
|---|
|  | 119 |  | 
|---|
|  | 120 | sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation | 
|---|
|  | 121 | sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator | 
|---|
|  | 122 | sout | sepEnable | 1 | 2 | 3 | endl;                            // globally turn on implicit separation | 
|---|
|  | 123 |  | 
|---|
|  | 124 | sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " " | 
|---|
|  | 125 | sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; | 
|---|
|  | 126 | sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", " | 
|---|
|  | 127 | sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; | 
|---|
|  | 128 |  | 
|---|
|  | 129 | sout | t1 | t2 | endl;                                                          // print tuple | 
|---|
| [829c907] | 130 |  | 
|---|
| [5a7966bb] | 131 | [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 }; | 
|---|
| [cb91437] | 132 | sout | [ 3, 4, "a", 7.2 ] | endl; | 
|---|
| [5a7966bb] | 133 | sout | t3 | endl; | 
|---|
| [829c907] | 134 | sepSetTuple( sout, " " ); | 
|---|
| [5a7966bb] | 135 | sout | t3 | endl; | 
|---|
|  | 136 | sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl; | 
|---|
| [829c907] | 137 | sepSet( sout, "^" ); | 
|---|
|  | 138 | sepSetTuple( sout, "-" ); | 
|---|
| [5a7966bb] | 139 | sout | t3 | 3 | 4 | t3 | endl; | 
|---|
| [53ba273] | 140 | } | 
|---|
|  | 141 |  | 
|---|
|  | 142 | // Local Variables: // | 
|---|
|  | 143 | // tab-width: 4 // | 
|---|
|  | 144 | // compile-command: "cfa io.c" // | 
|---|
|  | 145 | // End: // | 
|---|