mistake in tutorial re: stl vector
in the tutorial at cprogramming.com (this site) on stl vectors it states:
Quote:
Vectors are more powerful than arrays because the number of functions that are available for accessing and modifying vectors. Unfortunately, the [] operator still does not provide bounds checking. Let's take a look at several functions provided by the vector class:
Code:
unsigned int size(); Returns the number of elements in a vector
push_back(TYPE element); Adds an element to the end of a vector
swap(int x, int y); Swap elements x and y
bool empty(); Returns true if the vector is empty
void clear(); Erase all elements of the vector
...
Quote:
Code:
int main()
{
vector <int> example; //Vector to store integers
example.push_back(3); //Add 3 onto the vector
example.push_back(10); //Add 10 to the end
example.push_back(33); //Add 33 to the end
for(int x=0; x<example.size(); x++)
cout<<example[x]<<" "; //Should output: 3 10 33
if(!example.empty()) //Checks if empty
example.clear(); //Clears vector
vector <int> another_vector; //Creates another vector to store integers
another_vector.push_back(10); //Adds to end of vector
example.push_back(10); //Same
if(example==another_vector) //To show testing equality
example.push_back(20);
example.switch(1, 2); //Switches elements 1 and 2
for(int y=0; y<example.size(); y++)
cout<<example[y]<<" "; //Should output 20 10
return 0;
}
the above is clipped from this page
is switch really a vector class function? i get errors because i think it's mistaking it as the keyword switch.
is there some kind of swap function in vector arrays? if so, what's its syntax?