1. 程式人生 > >把編譯器的選擇項設置為最嚴格狀態

把編譯器的選擇項設置為最嚴格狀態

getc col 模板 argv back push pre getch iter

把編譯器的選擇項設置為最嚴格狀態。

 1 #include <iostream>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <vector>
 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 6 
 7 
 8 using namespace std;
 9 
10 //利用類模板生成實例
11 typedef vector < int
> IntArray; 12 13 //顯示數組 14 void put_array(int x[],int size) { 15 for(int i=0;i<size;i++) 16 cout<<x[i]<<" "; 17 cout<<endl; 18 } 19 20 //顯示vector容器中的元素 21 void put_vector(IntArray v) 22 { 23 IntArray::iterator theIterator; 24 25 for (theIterator=v.begin();theIterator!=v.end();++theIterator){
26 cout<<(*theIterator)<<" "; 27 } 28 cout<<endl; 29 } 30 31 //在main()函數中測試reverse()和reverse_copy()算法 32 int main(int argc, char** argv) { 33 34 //-------------------------------------------- 35 // reverse()和reverse_copy()算法對普通數組處理 36 //---------------------------------------------
37 int x[]={1,3,5,7,9}; 38 cout<<"x[]:"; 39 put_array(x,5); 40 41 //reverse()反轉x數組並顯示 42 reverse(x,x+5); 43 cout<<"x[]:"; 44 put_array(x,5); 45 46 int y[]={2,4,6,8,10}; 47 cout<<"y[]:"; 48 put_array(y,5); 49 50 //reverse_copy()反轉y數組的部分元素並拷貝到x數組第2個元素位置 51 reverse_copy(y+1,y+3,x+1); 52 cout<<"x[]:"; 53 put_array(x,5); 54 cout<<"y[]:"; 55 put_array(y,5); 56 //-------------------------------------------- 57 // reverse()和reverse_copy()算法對vector容器的處理 58 //--------------------------------------------- 59 //聲明intvector容器和叠代器ii 60 IntArray intvector; 61 62 //向intvector容器中插入元素 63 for (int i=1; i<=10; i++) { 64 intvector.push_back(i); 65 }; 66 67 //顯示intvector容器中的元素值 68 cout << "intvector: "<<endl; 69 put_vector(intvector); 70 71 //reverse()對於vector容器的處理 72 reverse(intvector.begin(),intvector.end()); 73 cout << "intvector: "<<endl; 74 put_vector(intvector); 75 76 // reverse_copy對於vector容器的處理 77 IntArray temp(5); 78 reverse_copy(intvector.begin()+2,intvector.begin()+7,temp.begin()); 79 cout << "temp: "<<endl; 80 put_vector(temp); 81 82 return 0; 83 }

把編譯器的選擇項設置為最嚴格狀態