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 |
---|
12 | // Last Modified On : Sun Jul 2 09:40:58 2017 |
---|
13 | // Update Count : 68 |
---|
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 | enum { size = 10 }; |
---|
35 | char s1[size], s2[size]; |
---|
36 | |
---|
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 | |
---|
44 | sout | "opening delimiters" | endl; |
---|
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 |
---|
56 | | endl | endl; |
---|
57 | |
---|
58 | sout | "closing delimiters" | endl; |
---|
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" |
---|
71 | | endl | endl; |
---|
72 | |
---|
73 | sout | "opening/closing delimiters" | endl; |
---|
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 |
---|
80 | | "\rx" |
---|
81 | | endl | endl; |
---|
82 | |
---|
83 | sout | "override opening/closing delimiters" | endl; |
---|
84 | sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; |
---|
85 | sout | endl; |
---|
86 | |
---|
87 | ifstream in; // create / open file |
---|
88 | open( &in, "io.data", "r" ); |
---|
89 | |
---|
90 | sout | "input bacis types" | endl; |
---|
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 |
---|
96 | sout | endl; |
---|
97 | |
---|
98 | sout | "output basic types" | endl; |
---|
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 |
---|
103 | sout | endl; |
---|
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; |
---|
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 |
---|
115 | sout | endl; |
---|
116 | |
---|
117 | sout | "change separator" | endl; |
---|
118 | sout | "from \" " | sepGet( sout ) | "\""; |
---|
119 | sepSet( sout, ", $" ); // change separator, maximum of 15 characters |
---|
120 | sout | "to \" " | sepGet( sout ) | "\"" | endl; |
---|
121 | sout | f | d | ld | endl |
---|
122 | | fc | dc | ldc | endl |
---|
123 | | s1 | s2 | endl |
---|
124 | | t1 | t2 | endl; // print tuple |
---|
125 | sout | endl; |
---|
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 |
---|
133 | sout | endl; |
---|
134 | |
---|
135 | sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start/end of line |
---|
136 | sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator |
---|
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; |
---|
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 |
---|
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; |
---|
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 |
---|
156 | sout | endl; |
---|
157 | |
---|
158 | [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 }; |
---|
159 | sout | [ 3, 4, "a", 7.2 ] | endl; |
---|
160 | sout | t3 | endl; |
---|
161 | sepSetTuple( sout, " " ); |
---|
162 | sout | t3 | endl; |
---|
163 | sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl; |
---|
164 | sepSet( sout, "^" ); |
---|
165 | sepSetTuple( sout, "-" ); |
---|
166 | sout | t3 | 3 | 4 | t3 | endl; |
---|
167 | } |
---|
168 | |
---|
169 | // Local Variables: // |
---|
170 | // tab-width: 4 // |
---|
171 | // compile-command: "cfa io.c" // |
---|
172 | // End: // |
---|