chapter11-14.cpp

来自「STL程序员开发指南源码」· C++ 代码 · 共 23 行

CPP
23
字号
//文件名:CHAPTER11-14.cpp
#include <vector>
#include <algorithm>
#include <iostream>
int main( ) {
   using namespace std;
   vector <int> v1;
   vector <int>::iterator Iter1;
   int i;
   for ( i = 0 ; i <= 9 ; i++ ){v1.push_back( i );}
   int ii;
   for ( ii = 0 ; ii <= 3 ; ii++ ) {v1.push_back( 7 );}
   random_shuffle (v1.begin( ), v1.end( ) );
   cout << "The original vector v1 is:\n ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
   cout << ")." << endl;
   // Replace elements with a value of 7 with a value of 700
   replace (v1.begin( ), v1.end( ), 7 , 700);
   cout << "The vector v1 with a value 700 replacing that of 7 is:\n ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
   cout << ")." << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?