// ========================================================================== // $Id: int_std_array.cpp,v 1.1 2014/09/13 19:48:03 jlang Exp $ // CSI2372 example Code for lecture 3 // ========================================================================== // (C)opyright: // // Jochen Lang // SITE, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.site.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@site.uottawa.ca // ========================================================================== // $Log: int_std_array.cpp,v $ // Revision 1.1 2014/09/13 19:48:03 jlang // Added C++11 features to lecture 3 // // Revision 1.2 2010/09/20 15:55:08 jlang // Improved output and names // // Revision 1.1 2010/09/20 15:51:04 jlang // Added basic std::vector example // // // ========================================================================== #include #include using std::cout; using std::endl; using std::array; /* * Basic use of std::array * * This is just a demo -- more usage later on. */ void manipulatePrint( std::array iArr_copy ) { cout << "Manipulate and print iArr_copy:" << endl; // loop over the elements for ( auto iter = iArr_copy.begin(); iter != iArr_copy.end(); ++iter ) { cout << ++(*iter) << " "; } cout << endl; return; } int main( int argc, char* argv[] ) { array iArr; // Make an integer array of size 10 and // leave it unitialized cout << "Uninitialized array: " << endl; for ( auto ele : iArr ) { cout << ele << " "; } cout << endl; int num = 0; // loop over the elements and set them to their rank // using an iterator cout << "Original sequence: " << endl; for ( auto iter = iArr.begin(); iter != iArr.end(); ++iter ) { *iter = num++; cout << *iter << " "; } cout << endl; // Copy the array to another array array oIArr = iArr; // Equal compare the arrays if ( oIArr == iArr ) { cout << "oIArr is the same as iArr" << endl; } // Pass the array to a function manipulatePrint( iArr ); // Not equal compare the arrays if ( oIArr != iArr ) { cout << "Now iArr has changed." << endl; } else { cout << "iArr sequence unchanged: " << endl; for ( auto ele : iArr ) { cout << ele << " "; } cout << endl; } return 0; }