[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 | // |
---|
[ef3403c6] | 7 | // io2.c -- |
---|
[53ba273] | 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Wed Mar 2 16:56:02 2016 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[ef3403c6] | 12 | // Last Modified On : Thu May 24 21:17:41 2018 |
---|
| 13 | // Update Count : 103 |
---|
[53ba273] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream> |
---|
| 17 | |
---|
| 18 | int main() { |
---|
[5f20b30] | 19 | _Bool b; // basic types |
---|
| 20 | char c; |
---|
[cd218e8] | 21 | signed char sc; |
---|
| 22 | unsigned char usc; |
---|
[53ba273] | 23 | short int si; |
---|
| 24 | unsigned short int usi; |
---|
| 25 | int i; |
---|
| 26 | unsigned int ui; |
---|
| 27 | long int li; |
---|
| 28 | unsigned long int uli; |
---|
| 29 | long long int lli; |
---|
| 30 | unsigned long long int ulli; |
---|
| 31 | float f; |
---|
| 32 | double d; |
---|
| 33 | long double ld; |
---|
| 34 | float _Complex fc; |
---|
| 35 | double _Complex dc; |
---|
| 36 | long double _Complex ldc; |
---|
[5a7966b] | 37 | enum { size = 10 }; |
---|
| 38 | char s1[size], s2[size]; |
---|
[53ba273] | 39 | |
---|
[09687aa] | 40 | ifstream in = { "io.data" }; // create / open file |
---|
[53ba273] | 41 | |
---|
[86f384b] | 42 | sout | "input bacis types" | endl; |
---|
[5f20b30] | 43 | in | b // boolean |
---|
| 44 | | c | sc | usc // character |
---|
[09687aa] | 45 | | si | usi | i | ui | li | uli | lli | ulli // integral |
---|
| 46 | | f | d | ld // floating point |
---|
| 47 | | fc | dc | ldc // floating-point complex |
---|
| 48 | | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked |
---|
[86f384b] | 49 | sout | endl; |
---|
[53ba273] | 50 | |
---|
[86f384b] | 51 | sout | "output basic types" | endl; |
---|
[5f20b30] | 52 | sout | b | endl // boolean |
---|
| 53 | | c | ' ' | sc | ' ' | usc | endl // character |
---|
[09687aa] | 54 | | si | usi | i | ui | li | uli | lli | ulli | endl // integral |
---|
| 55 | | f | d | ld | endl // floating point |
---|
| 56 | | fc | dc | ldc | endl; // complex |
---|
[53ba273] | 57 | sout | endl; |
---|
[86f384b] | 58 | |
---|
| 59 | sout | "tuples" | endl; |
---|
[53a6c2a] | 60 | [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; |
---|
[86f384b] | 61 | sout | t1 | t2 | endl; // print tuple |
---|
| 62 | sout | endl; |
---|
| 63 | |
---|
| 64 | sout | "toggle separator" | endl; |
---|
[5a7966b] | 65 | sout | f | "" | d | "" | ld | endl // floating point without separator |
---|
[09687aa] | 66 | | sepDisable | fc | dc | ldc | endl // complex without separator |
---|
| 67 | | fc | sepOn | dc | ldc | endl // local separator add |
---|
| 68 | | sepEnable | fc | dc | ldc | endl // complex with separator |
---|
| 69 | | fc | sepOff | dc | ldc | endl // local separator removal |
---|
| 70 | | s1 | sepOff | s2 | endl // local separator removal |
---|
| 71 | | s1 | "" | s2 | endl; // local separator removal |
---|
[53ba273] | 72 | sout | endl; |
---|
| 73 | |
---|
[86f384b] | 74 | sout | "change separator" | endl; |
---|
[53a6c2a] | 75 | sout | "from \"" | sep | "\""; |
---|
[5a7966b] | 76 | sepSet( sout, ", $" ); // change separator, maximum of 15 characters |
---|
[53a6c2a] | 77 | sout | " to \"" | sep | "\"" | endl; |
---|
[829c907] | 78 | sout | f | d | ld | endl |
---|
[09687aa] | 79 | | fc | dc | ldc | endl |
---|
| 80 | | s1 | s2 | endl |
---|
| 81 | | t1 | t2 | endl; // print tuple |
---|
[d395012] | 82 | sout | endl; |
---|
[53a6c2a] | 83 | sout | "from \"" | sep | "\" "; |
---|
[86f384b] | 84 | sepSet( sout, " " ); // restore separator |
---|
[53a6c2a] | 85 | sout | "to \"" | sep | "\"" | endl; |
---|
[86f384b] | 86 | sout | f | d | ld | endl |
---|
[09687aa] | 87 | | fc | dc | ldc | endl |
---|
| 88 | | s1 | s2 | endl |
---|
| 89 | | t1 | t2 | endl; // print tuple |
---|
[d395012] | 90 | sout | endl; |
---|
[6b6597c] | 91 | |
---|
[53a6c2a] | 92 | sout | "check sepOn/sepOff" | endl; |
---|
| 93 | sout | sepOn | 1 | 2 | 3 | sepOn | endl; // no separator at start/end of line |
---|
[5a7966b] | 94 | sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator |
---|
[53a6c2a] | 95 | sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line |
---|
| 96 | sout | 1 | 2 | 3 | "\n\n" | sepOn; // no separator at start of next line |
---|
[d395012] | 97 | sout | 1 | 2 | 3 | endl; |
---|
| 98 | sout | endl; |
---|
[5a7966b] | 99 | |
---|
[53a6c2a] | 100 | sout | "check enable/disable" | endl; |
---|
[5a7966b] | 101 | sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation |
---|
| 102 | sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator |
---|
[d395012] | 103 | sout | sepEnable | 1 | 2 | 3 | endl | sepDisable; // globally turn on/off implicit separation |
---|
| 104 | sout | 1 | 2 | 3 | endl | sepEnable; // globally turn on implicit separation |
---|
| 105 | sout | 1 | 2 | 3 | sepOn | sepDisable | endl; // ignore seperate at end of line |
---|
| 106 | sout | 1 | 2 | 3 | sepOn | sepEnable | endl; // separator at end of line |
---|
| 107 | sout | 1 | 2 | 3 | endl; |
---|
| 108 | sout | endl; |
---|
[5a7966b] | 109 | |
---|
[53a6c2a] | 110 | // sout | fmt( d, "%8.3f" ) || endl; |
---|
| 111 | // sout | endl; |
---|
| 112 | |
---|
[5a7966b] | 113 | sepSetTuple( sout, " " ); // set tuple separator from ", " to " " |
---|
[53a6c2a] | 114 | sout | t1 | t2 | " \"" | sep | "\"" | endl; |
---|
[5a7966b] | 115 | sepSetTuple( sout, ", " ); // reset tuple separator to ", " |
---|
[53a6c2a] | 116 | sout | t1 | t2 | " \"" | sep | "\"" | endl; |
---|
[5a7966b] | 117 | sout | t1 | t2 | endl; // print tuple |
---|
[d395012] | 118 | sout | endl; |
---|
[829c907] | 119 | |
---|
[5a7966b] | 120 | [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 }; |
---|
[cb91437] | 121 | sout | [ 3, 4, "a", 7.2 ] | endl; |
---|
[5a7966b] | 122 | sout | t3 | endl; |
---|
[829c907] | 123 | sepSetTuple( sout, " " ); |
---|
[5a7966b] | 124 | sout | t3 | endl; |
---|
| 125 | sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl; |
---|
[829c907] | 126 | sepSet( sout, "^" ); |
---|
| 127 | sepSetTuple( sout, "-" ); |
---|
[5a7966b] | 128 | sout | t3 | 3 | 4 | t3 | endl; |
---|
[53ba273] | 129 | } |
---|
| 130 | |
---|
| 131 | // Local Variables: // |
---|
| 132 | // tab-width: 4 // |
---|
[ef3403c6] | 133 | // compile-command: "cfa io2.c" // |
---|
[53ba273] | 134 | // End: // |
---|