source: src/examples/vector_test.c @ 13ca524

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 13ca524 was e56cfdb0, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

allow nested routines to use type variables in containing scope, fix missing adapters, generalized iostream write

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[86bd7c1f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 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// vector_test.c --
8//
9// Author           : Richard C. Bilson
10// Created On       : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
[e56cfdb0]12// Last Modified On : Thu Nov 19 17:54:34 2015
13// Update Count     : 9
[86bd7c1f]14//
15
[51b7345]16#include "fstream.h"
17#include "vector_int.h"
18#include "array.h"
[134b86a]19#include "iterator.h"
[51b7345]20
[134b86a]21int main() {
[86bd7c1f]22        ofstream *sout = ofstream_stdout();
23        ifstream *sin = ifstream_stdin();
24        vector_int vec = vector_int_allocate();
[134b86a]25
[86bd7c1f]26        // read in numbers until EOF or error
27        int num;
[134b86a]28
[86bd7c1f]29        sout << "enter N elements and C-d on a separate line:\n";
30        for ( ;; ) {
[e56cfdb0]31                sin >> &num;
[86bd7c1f]32          if ( fail( sin ) || eof( sin ) ) break;
[e56cfdb0]33                append( &vec, num );
[86bd7c1f]34        }
35        // write out the numbers
[134b86a]36
[86bd7c1f]37        sout << "Array elements:\n";
[e56cfdb0]38        write( begin( vec ), end( vec ), sout );
[86bd7c1f]39        sout << "\n";
[e56cfdb0]40
[86bd7c1f]41        sout << "Array elements reversed:\n";
42        write_reverse( begin( vec ), end( vec ), sout );
43        sout << "\n";
[51b7345]44}
[134b86a]45
[86bd7c1f]46// Local Variables: //
47// tab-width: 4 //
48// compile-command: "cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o" //
49// End: //
Note: See TracBrowser for help on using the repository browser.