ARTICLE AD BOX
Suppose I have to manipulate the values inside a vector defined in C++ and the manipulation operation is to obtain the square of each value inside the vector
#include<vector> #include<iostream> void printVector(std::vector<int> v){ std::cout << "[ "; for(const auto& value : v) std::cout<<value<<" "; std::cout << "]"; } int main(){ std::vector v{1,2,3,4,5}; std::size_t size_of_vector{v.size()}; printVector(v); for(std::size_t index{0}; index < size_of_vector; ++index){ v[index]=v[index]*v[index]; } printVector(v); }This block of code does the operation.
But are there any other efficient methods to do this ?
