    01: #include <iostream>
    02: #include <string>
    03: #include <vector>
    04:
    05: using namespace std;
    06:
    07: /**
    08:    Inserts an element into a vector.
    09:    @param v a vector
    10:    @param pos the position before which to insert the element
    11:    @param s the element to insert
    12: */
    13: void insert(vector<string>& v, int pos, string s)
    14: {
    15:    int last = v.size() - 1;
    16:    v.push_back(v[last]);
    17:    for (int i = last; i > pos; i--)
    18:       v[i] = v[i - 1];
    19:    v[pos] = s;
    20: }
    21:
    22: /**
    23:    Prints all elements in a vector.
    24:    @param v the vector to print
    25: */
    26: void print(vector<string> v)
    27: {
    28:    for (int i = 0; i < v.size(); i++)
    29:       cout << "[" << i << "] " << v[i] << "\n";
    30: }
    31:
    32: int main()
    33: {
    34:    vector<string> staff(5);
    35:    staff[0] = "Cracker, Carl";
    36:    staff[1] = "Hacker, Harry";
    37:    staff[2] = "Lam, Larry";
    38:    staff[3] = "Reindeer, Rudolf";
    39:    staff[4] = "Sandman, Susan";
    40:    print(staff);
    41:
    42:    int pos;
    43:    cout << "Insert before which element? ";
    44:    cin >> pos;
    45:
    46:    insert(staff, pos, "New, Nina");
    47:    print(staff);
    48:    return 0;
    49: }