//tstVect.cpp -- @CopyLeft by tsaiwn@csie.nctu.edu.tw //test STL , and as well as my "vector" #include "vector" //use my "vector" if there is one in current directory; else use STL #include #include using namespace std; template void print(vector &x) { typename vector::iterator it; for(int i=0; i < x.size( ); ++i) cout << " "<< x[i]; cout << endl; cout<< "size, capa= "< x(bb, bb+5); // only first 5 elements vector y; cout << "x: "; print(x); cout << "y: "; print(y); //cout<< "y.front, back="<< y.front( )<<", "<< y.back( )< cout << "x: "; print(x); cout << "x[92]===" << x[92]<< "; do x.at(2)=222 ::: "; x.at(2) = 222; cout << x.at(2) <<" ::: "<g++ tstVector.cpp C:\testc\STL>a x: X 12 X 28 X 3 X 4 X 58 size, capa= 5, 5; head, tail=12, 58; front, back=12, 58 y: size, capa= 0, 10; NOTHING ===now do add 999 to x; add three nums to y X x[2] = 3 X X x[2] = 333 x: X 12 X 28 X 333 X 4 X 58 X 999 size, capa= 6, 10; head, tail=12, 999; front, back=12, 999 y: X 3.8 X 8.5 X 4.9 size, capa= 3, 10; head, tail=3.8, 4.9; front, back=3.8, 4.9 now do sort(x.begin( ), x.end( )); x: X 4 X 12 X 28 X 58 X 333 X 999 size, capa= 6, 10; head, tail=4, 999; front, back=4, 999 X x[92]===1818838560; do x.at(2)=222 ::: A A 222 ::: 222 A This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. //======== /// 以下是用到 C++ STL 的 //////////////// C:\testc\STL>ren vector vectorME C:\testc\STL>g++ tstVector.cpp C:\testc\STL>a x: 12 28 3 4 58 size, capa= 5, 5; head, tail=12, 58; front, back=12, 58 y: size, capa= 0, 0; NOTHING ===now do add 999 to x; add three nums to y x[2] = 3 x[2] = 333 x: 12 28 333 4 58 999 size, capa= 6, 10; head, tail=12, 999; front, back=12, 999 y: 3.8 8.5 4.9 size, capa= 3, 4; head, tail=3.8, 4.9; front, back=3.8, 4.9 now do sort(x.begin( ), x.end( )); x: 4 12 28 58 333 999 size, capa= 6, 10; head, tail=4, 999; front, back=4, 999 x[92]===1750359155; do x.at(2)=222 ::: 222 ::: 222 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. *********************/