1 //tstVect.cpp -- @CopyLeft by tsaiwn@csie.nctu.edu.tw 2 //test STL , and as well as my "vector" 3 #include "vector" 4 //use my "vector" if there is one in current directory; else use STL 5 #include 6 #include 7 using namespace std; 8 template void print(vector &x) { 9 typename vector::iterator it; 10 for(int i=0; i < x.size( ); ++i) cout << " "<< x[i]; cout << endl; 11 cout<< "size, capa= "< x(bb, bb+5); // only first 5 elements 18 vector y; 19 cout << "x: "; print(x); cout << "y: "; print(y); 20 //cout<< "y.front, back="<< y.front( )<<", "<< y.back( )< 29 cout << "x: "; print(x); 30 cout << "x[92]===" << x[92]<< "; do x.at(2)=222 ::: "; 31 x.at(2) = 222; cout << x.at(2) <<" ::: "<g++ tstVector.cpp 37 C:\testc\STL>a 38 x: X 12 X 28 X 3 X 4 X 58 39 size, capa= 5, 5; head, tail=12, 58; front, back=12, 58 40 y: 41 size, capa= 0, 10; NOTHING 42 ===now do add 999 to x; add three nums to y 43 X x[2] = 3 44 X X x[2] = 333 45 x: X 12 X 28 X 333 X 4 X 58 X 999 46 size, capa= 6, 10; head, tail=12, 999; front, back=12, 999 47 y: X 3.8 X 8.5 X 4.9 48 size, capa= 3, 10; head, tail=3.8, 4.9; front, back=3.8, 4.9 49 now do sort(x.begin( ), x.end( )); 50 x: X 4 X 12 X 28 X 58 X 333 X 999 51 size, capa= 6, 10; head, tail=4, 999; front, back=4, 999 52 X x[92]===1818838560; do x.at(2)=222 ::: A A 222 ::: 222 53 A 54 This application has requested the Runtime to terminate it in an unusual way. 55 Please contact the application's support team for more information. 56 //======== /// 以下是用到 C++ STL 的 //////////////// 57 C:\testc\STL>ren vector vectorME 58 C:\testc\STL>g++ tstVector.cpp 59 C:\testc\STL>a 60 x: 12 28 3 4 58 61 size, capa= 5, 5; head, tail=12, 58; front, back=12, 58 62 y: 63 size, capa= 0, 0; NOTHING 64 ===now do add 999 to x; add three nums to y 65 x[2] = 3 66 x[2] = 333 67 x: 12 28 333 4 58 999 68 size, capa= 6, 10; head, tail=12, 999; front, back=12, 999 69 y: 3.8 8.5 4.9 70 size, capa= 3, 4; head, tail=3.8, 4.9; front, back=3.8, 4.9 71 now do sort(x.begin( ), x.end( )); 72 x: 4 12 28 58 333 999 73 size, capa= 6, 10; head, tail=4, 999; front, back=4, 999 74 x[92]===1750359155; do x.at(2)=222 ::: 222 ::: 222 75 76 This application has requested the Runtime to terminate it in an unusual way. 77 Please contact the application's support team for more information. 78 *********************/