在使用vector<>中我有一个小问题,比如vector<string>做string的数组,可以用pash_back()输入,我想知道,怎样把指针指到任何一个已经输入的string的头???
在使用vector<>中我有一个小问题,比如vector<string>做string的数组,可以用pash_back()输入,我想知道,怎样把指针指到任何一个已经输入的string的头???
reference front( );
const_reference front( ) const;
///////////////////////////////////
for example:
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
v1.push_back( 10 );
v1.push_back( 11 );
v1.push_back( 12 );
int& i = v1.front( );
const int& ii = v1.front( );
cout << "The first integer of v1 is "<< i << endl;
i++;
cout << "The second integer of v1 is "<< ii << endl;
}
output:
The first integer of v1 is 10
The second integer of v1 is 11
include <queue>
#include <iostream>
int main() {
using namespace std;
queue <int> q1;
q1.push( 10 );
q1.push( 20 );
q1.push( 30 );
queue <int>::size_type i;
i = q1.size( );
cout << "The queue length is " << i << "." << endl;
int& ii = q1.back( );
int& iii = q1.front( );
cout << "The integer at the back of queue q1 is " << ii
<< "." << endl;
cout << "The integer at the front of queue q1 is " << iii
<< "." << endl;
}