[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 |
---|
[cb91437] | 12 | // Last Modified On : Tue Mar 21 22:36:06 2017 |
---|
| 13 | // Update Count : 48 |
---|
[53ba273] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream> |
---|
| 17 | |
---|
| 18 | int main() { |
---|
| 19 | char c; // basic types |
---|
| 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; |
---|
| 34 | char s1[10], s2[10]; |
---|
| 35 | |
---|
[58b5d03] | 36 | int x = 3, y = 5, z = 7; |
---|
| 37 | sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; |
---|
| 38 | sout | 1 | 2 | 3 | endl; |
---|
| 39 | sout | '1' | '2' | '3' | endl; |
---|
| 40 | sout | 1 | "" | 2 | "" | 3 | endl; |
---|
| 41 | sout | endl; |
---|
| 42 | |
---|
[53ba273] | 43 | ifstream in; // create / open file |
---|
[6b6597c] | 44 | open( &in, "io.data", "r" ); |
---|
[53ba273] | 45 | |
---|
| 46 | &in | &c // character |
---|
| 47 | | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli // integral |
---|
| 48 | | &f | &d | &ld // floating point |
---|
| 49 | | &fc | &dc | &ldc // floating-point complex |
---|
| 50 | | cstr( s1 ) | cstr( s2, 10 ); // C string, length unchecked and checked |
---|
| 51 | |
---|
| 52 | sout | c | ' ' | endl // character |
---|
| 53 | | si | usi | i | ui | li | uli | lli | ulli | endl // integral |
---|
| 54 | | f | d | ld | endl // floating point |
---|
| 55 | | fc | dc | ldc | endl; // complex |
---|
| 56 | sout | endl; |
---|
| 57 | sout | f | "" | d | "" | ld | endl // floating point without separator |
---|
| 58 | | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator |
---|
| 59 | | sepOn | s1 | sepOff | s2 | endl // local separator removal |
---|
[b72bad4f] | 60 | | s1 | "" | s2 | endl; // C string without separator |
---|
[53ba273] | 61 | sout | endl; |
---|
| 62 | |
---|
| 63 | sepSet( sout, ", $" ); // change separator, maximum of 15 characters |
---|
[829c907] | 64 | sout | f | d | ld | endl |
---|
| 65 | | fc | dc | ldc | endl |
---|
[53ba273] | 66 | | s1 | s2 | endl; |
---|
[6b6597c] | 67 | sout | endl; |
---|
| 68 | sepSet( sout, " " ); |
---|
| 69 | |
---|
| 70 | sout |
---|
| 71 | // opening delimiters |
---|
| 72 | | "v(" | 27 |
---|
| 73 | | "v[" | 27 |
---|
| 74 | | "v{" | 27 |
---|
| 75 | | "$" | 27 |
---|
[829c907] | 76 | | "=" | 27 |
---|
[6b6597c] | 77 | | "£" | 27 |
---|
| 78 | | "¥" | 27 |
---|
[e945826] | 79 | | "¡" | 27 |
---|
[6b6597c] | 80 | | "¿" | 27 |
---|
| 81 | | "«" | 27 |
---|
| 82 | | endl |
---|
| 83 | // closing delimiters |
---|
| 84 | | 25 | "," |
---|
| 85 | | 25 | "." |
---|
| 86 | | 25 | ":" |
---|
| 87 | | 25 | ";" |
---|
| 88 | | 25 | "!" |
---|
| 89 | | 25 | "?" |
---|
| 90 | | 25 | "%" |
---|
| 91 | | 25 | "¢" |
---|
| 92 | | 25 | "»" |
---|
[829c907] | 93 | | 25 | ")" |
---|
| 94 | | 25 | "]" |
---|
| 95 | | 25 | "}" |
---|
[6b6597c] | 96 | | endl |
---|
| 97 | // opening-closing delimiters |
---|
| 98 | | 25 | "'" | 27 |
---|
| 99 | | 25 | "`" | 27 |
---|
| 100 | | 25 | "\"" | 27 |
---|
[dd51906] | 101 | | 25 | " " | 27 |
---|
[6b6597c] | 102 | | 25 | "\f" | 27 |
---|
| 103 | | 25 | "\n" | 27 |
---|
| 104 | | 25 | "\r" | 27 |
---|
| 105 | | 25 | "\t" | 27 |
---|
| 106 | | 25 | "\v" | 27 |
---|
| 107 | | endl; |
---|
[829c907] | 108 | |
---|
| 109 | [int, int, const char *, double] t = { 3, 4, "a", 7.2 }; |
---|
[cb91437] | 110 | sout | [ 3, 4, "a", 7.2 ] | endl; |
---|
[829c907] | 111 | sout | t | endl; |
---|
| 112 | sepSetTuple( sout, " " ); |
---|
| 113 | sout | t | endl; |
---|
| 114 | sout | sepOn | t | sepDisable | t | sepEnable | t | endl; |
---|
| 115 | sepSet( sout, "^" ); |
---|
| 116 | sepSetTuple( sout, "-" ); |
---|
| 117 | sout | t | 3 | 4 | t | endl; |
---|
[53ba273] | 118 | } |
---|
| 119 | |
---|
| 120 | // Local Variables: // |
---|
| 121 | // tab-width: 4 // |
---|
| 122 | // compile-command: "cfa io.c" // |
---|
| 123 | // End: // |
---|