CHAPTER5-3.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER5-3.cpp
- #include <iostream>
- #include <vector>
- using namespace std;
- void print (vector < double >& vector_)
- { for (int i = 0; i < vector_.size (); i++) cout << vector_[i] << " ";
- cout << endl;
- }
- int main ()
- { vector < double > v1; // 定义了一空的类型为double的vector向量.
- v1.push_back (32.1); //插入值到向量中
- v1.push_back (40.5);
- vector< double > v2; // 定义另外一个向量
- v2.push_back (3.56);
- cout << "v1 = ";
- print (v1);
- cout << "v2 = ";
- print (v2);
- v1.swap (v2); // 两个向量的内容进行交换
- cout << "v1 = ";
- print (v1);
- cout << "v2 = ";
- print (v2);
- v2 = v1; //把v1中的元素赋值给v2
- cout << "v2 = ";
- print (v2);
- return 0;
- }