Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ Vector Operation Change Elements

#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> num {1, 2, 3, 4, 5};

  cout << "Initial Vector: ";

  for (const int& i : num) {
    cout << i << "  ";
  }

  // change elements at indexes 0 and 3
  num.at(0) = 5;
  num.at(3) = 15;

  cout << "
Updated Vector: ";

  for (const int& i : num) {
    cout << i << "  ";
  }

  return 0;
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Vector #Operation #Change #Elements
ADD COMMENT
Topic
Name
4+8 =