Vector operators(Vector 操作符)
Syntax:
语法:
#include <vector> T& operator[]( size_type index ); const T& operator[]( size_type index ) const; vector& operator=(const vector& c2); bool operator==(const vector& c1, const vector& c2); bool operator!=(const vector& c1, const vector& c2); bool operator<(const vector& c1, const vector& c2); bool operator>(const vector& c1, const vector& c2); bool operator<=(const vector& c1, const vector& c2); bool operator>=(const vector& c1, const vector& c2);
All of the C++ containers can be compared and assigned with the standard comparison operators: ==, !=, %%<=%%, >=, <, >, and =. Individual elements of a vector can be examined with the [] operator.
所有的 C++ 容器都可以使用比较操作符:==,!=,%%<=%%,>=,<,>,和 = 来比较赋值。单个的 vector 元素可以使用 [] 操作符来检查。
Performing a comparison or assigning one vector to another takes linear time.
执行两个 vector 之间的比较和赋值将花费 linear time。
The [] operator runs in constant time.
而操作符 [] 运行将花费 constant time。
Two vectors are equal if:
满足下面两个条件的 vector 是相等的:
- Their size is the same, and (包含的元素个数是一样的,即 size 是相同的,) -
- Each member in location i in one vect or is equal to the the member in location i in the other vector.(两个 vector 中相同位置上的元素值是相等的。)
Comparisons among vectors are done lexicographically.
vectors 之间的比较是按字典顺序执行。
For example, the following code uses the [] operator to access all of the elements of a vector:
例如,下面的代码使用 [] 操作符来访问 vector 的所有元素:
vector<int> v( 5, 1 ); for( int i = 0; i < v.size(); i++ ) { cout << "Element " << i << " is " << v[i] << endl; }
Related Topics: at
相关主题: at