Search
 
SCRIPT & CODE EXAMPLE
 

CPP

vector modify elements cpp

vector<string> vec;
vec.push_back(new string()); // allocate
vec[0]="hello"; // assign/modify
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: memset function in c++ 
Cpp :: know what the input data is whether integer or not 
Cpp :: not c++ 
Cpp :: flutter text direction auto 
Cpp :: how to modify 2d array in function c++ 
Cpp :: malloc 2d array cpp 
Cpp :: bubble sort function in c++ 
Cpp :: c++ custom printf 
Cpp :: An Array declaration by initializing elements in C++ 
Cpp :: ue4 c++ switch enum 
Cpp :: logisch oder 
Cpp :: cpp serial print override always in same place 
Cpp :: read a file line by line c++ struct site:stackoverflow.com 
Cpp :: vector insert to end 
Cpp :: remove item from layout 
Cpp :: how to increase the length of a string 
Cpp :: how does sorting array works in c++ 
Cpp :: error c4001 site:docs.microsoft.com 
Cpp :: print all substrings in c++ 
Cpp :: how to open file without override c++ 
Cpp :: how to make a defaule conrstrocr in c++ classes 
Cpp :: how to change the icon of an exe in c++ 
Cpp :: c++ program that put a space in between characters 
Cpp :: unions c++ 
Cpp :: c++ scanf always expects double and not float 
Cpp :: C++ meaning :: 
Cpp :: time function in c++ 
Cpp :: libraries required for gaming in c++ 
Cpp :: print an array c++ 
Cpp :: char to binary 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =