I'm trying to insert an integer into my vector, but my teacher doesn't wont me to use the insert function. I've look for an alternative, but I keep finding tutorials on insert functions. Can anyone help me insert the integer 5 between element 4 and 5?
#include <iostream>
#include <vector>
using namespace std;
void printVector(vector<int> b)
{
for(int i = 0; i < b.size(); i++)
{
cout << b[i] << endl;
}
#include <iostream>
#include <vector>
usingnamespace std;
int main()
{
vector<int> vectorOfInt; // Creating the vector
int x = 10;
int y = 22;
vectorOfInt.push_back(x); // Adding x to the vector.
// Looping trough the vector to print elements value.
for (int i = 0; i < vectorOfInt.size(); i++)
{
cout << vectorOfInt[i] << " ";
}
cout << endl;
vectorOfInt.push_back(y); // Adding y to the vector.
// Looping trough the vector to print elements value.
for (int i = 0; i < vectorOfInt.size(); i++)
{
cout << vectorOfInt[i] << " ";
}
cout << endl;
system("pause");
}