[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 |
---|
[86f384b] | 12 | // Last Modified On : Sun Jul 2 09:40:58 2017 |
---|
| 13 | // Update Count : 68 |
---|
[53ba273] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream> |
---|
| 17 | |
---|
| 18 | int main() { |
---|
[5a7966b] | 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; |
---|
[5a7966b] | 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 | |
---|
[86f384b] | 44 | sout | "opening delimiters" | endl; |
---|
[5a7966b] | 45 | sout |
---|
| 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 |
---|
[86f384b] | 56 | | endl | endl; |
---|
| 57 | |
---|
| 58 | sout | "closing delimiters" | endl; |
---|
[5a7966b] | 59 | sout |
---|
| 60 | | 1 | ", x" |
---|
| 61 | | 2 | ". x" |
---|
| 62 | | 3 | "; x" |
---|
| 63 | | 4 | "! x" |
---|
| 64 | | 5 | "? x" |
---|
| 65 | | 6 | "% x" |
---|
| 66 | | 7 | "¢ x" |
---|
| 67 | | 8 | "» x" |
---|
| 68 | | 9 | ") x" |
---|
| 69 | | 10 | "] x" |
---|
| 70 | | 11 | "} x" |
---|
[86f384b] | 71 | | endl | endl; |
---|
| 72 | |
---|
| 73 | sout | "opening/closing delimiters" | endl; |
---|
[5a7966b] | 74 | sout |
---|
| 75 | | "x`" | 1 | "`x'" | 2 |
---|
| 76 | | "'x\"" | 3 | "\"x:" | 4 |
---|
| 77 | | ":x " | 5 | " x\t" | 6 |
---|
| 78 | | "\tx\f" | 7 | "\fx\v" | 8 |
---|
| 79 | | "\vx\n" | 9 | "\nx\r" | 10 |
---|
[86f384b] | 80 | | "\rx" |
---|
| 81 | | endl | endl; |
---|
| 82 | |
---|
| 83 | sout | "override opening/closing delimiters" | endl; |
---|
[5a7966b] | 84 | sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; |
---|
[86f384b] | 85 | sout | endl; |
---|
[5a7966b] | 86 | |
---|
| 87 | ifstream in; // create / open file |
---|
[6b6597c] | 88 | open( &in, "io.data", "r" ); |
---|
[53ba273] | 89 | |
---|
[86f384b] | 90 | sout | "input bacis types" | endl; |
---|
[5a7966b] | 91 | &in | &c // character |
---|
| 92 | | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli // integral |
---|
| 93 | | &f | &d | &ld // floating point |
---|
| 94 | | &fc | &dc | &ldc // floating-point complex |
---|
| 95 | | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked |
---|
[86f384b] | 96 | sout | endl; |
---|
[53ba273] | 97 | |
---|
[86f384b] | 98 | sout | "output basic types" | endl; |
---|
[5a7966b] | 99 | sout | c | ' ' | endl // character |
---|
| 100 | | si | usi | i | ui | li | uli | lli | ulli | endl // integral |
---|
| 101 | | f | d | ld | endl // floating point |
---|
| 102 | | fc | dc | ldc | endl; // complex |
---|
[53ba273] | 103 | sout | endl; |
---|
[86f384b] | 104 | |
---|
| 105 | sout | "tuples" | endl; |
---|
| 106 | [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; |
---|
| 107 | sout | t1 | t2 | endl; // print tuple |
---|
| 108 | sout | endl; |
---|
| 109 | |
---|
| 110 | sout | "toggle separator" | endl; |
---|
[5a7966b] | 111 | sout | f | "" | d | "" | ld | endl // floating point without separator |
---|
| 112 | | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator |
---|
| 113 | | sepOn | s1 | sepOff | s2 | endl // local separator removal |
---|
| 114 | | s1 | "" | s2 | endl; // C string without separator |
---|
[53ba273] | 115 | sout | endl; |
---|
| 116 | |
---|
[86f384b] | 117 | sout | "change separator" | endl; |
---|
| 118 | sout | "from \" " | sepGet( sout ) | "\""; |
---|
[5a7966b] | 119 | sepSet( sout, ", $" ); // change separator, maximum of 15 characters |
---|
[86f384b] | 120 | sout | "to \" " | sepGet( sout ) | "\"" | endl; |
---|
[829c907] | 121 | sout | f | d | ld | endl |
---|
[5a7966b] | 122 | | fc | dc | ldc | endl |
---|
[86f384b] | 123 | | s1 | s2 | endl |
---|
| 124 | | t1 | t2 | endl; // print tuple |
---|
[d395012] | 125 | sout | endl; |
---|
[86f384b] | 126 | sout | "from \"" | sepGet( sout ) | "\""; |
---|
| 127 | sepSet( sout, " " ); // restore separator |
---|
| 128 | sout | "to \"" | sepGet( sout ) | "\"" | endl; |
---|
| 129 | sout | f | d | ld | endl |
---|
| 130 | | fc | dc | ldc | endl |
---|
| 131 | | s1 | s2 | endl |
---|
| 132 | | t1 | t2 | endl; // print tuple |
---|
[d395012] | 133 | sout | endl; |
---|
[6b6597c] | 134 | |
---|
[d395012] | 135 | sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start/end of line |
---|
[5a7966b] | 136 | sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator |
---|
[d395012] | 137 | sout | sepOn | 1 | 2 | 3 | sepOn | sepOff | endl; // separator at start of line |
---|
| 138 | sout | 1 | 2 | 3 | endl | sepOn; // separator at start of next line |
---|
| 139 | sout | 1 | 2 | 3 | endl; |
---|
| 140 | sout | endl; |
---|
[5a7966b] | 141 | |
---|
| 142 | sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation |
---|
| 143 | sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator |
---|
[d395012] | 144 | sout | sepEnable | 1 | 2 | 3 | endl | sepDisable; // globally turn on/off implicit separation |
---|
| 145 | sout | 1 | 2 | 3 | endl | sepEnable; // globally turn on implicit separation |
---|
| 146 | sout | 1 | 2 | 3 | sepOn | sepDisable | endl; // ignore seperate at end of line |
---|
| 147 | sout | 1 | 2 | 3 | sepOn | sepEnable | endl; // separator at end of line |
---|
| 148 | sout | 1 | 2 | 3 | endl; |
---|
| 149 | sout | endl; |
---|
[5a7966b] | 150 | |
---|
| 151 | sepSetTuple( sout, " " ); // set tuple separator from ", " to " " |
---|
| 152 | sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; |
---|
| 153 | sepSetTuple( sout, ", " ); // reset tuple separator to ", " |
---|
| 154 | sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; |
---|
| 155 | sout | t1 | t2 | endl; // print tuple |
---|
[d395012] | 156 | sout | endl; |
---|
[829c907] | 157 | |
---|
[5a7966b] | 158 | [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 }; |
---|
[cb91437] | 159 | sout | [ 3, 4, "a", 7.2 ] | endl; |
---|
[5a7966b] | 160 | sout | t3 | endl; |
---|
[829c907] | 161 | sepSetTuple( sout, " " ); |
---|
[5a7966b] | 162 | sout | t3 | endl; |
---|
| 163 | sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl; |
---|
[829c907] | 164 | sepSet( sout, "^" ); |
---|
| 165 | sepSetTuple( sout, "-" ); |
---|
[5a7966b] | 166 | sout | t3 | 3 | 4 | t3 | endl; |
---|
[53ba273] | 167 | } |
---|
| 168 | |
---|
| 169 | // Local Variables: // |
---|
| 170 | // tab-width: 4 // |
---|
| 171 | // compile-command: "cfa io.c" // |
---|
| 172 | // End: // |
---|