c++ iterate through vectgor
std::vector<int> vec_of_ints(10, 1); // 10 ints all with value 1
for (int i : vec_of_ints) { // use auto for more complex types
std::cout << vec_of_ints.at(i) << " ";
}
std::cout << std::endl;
c++ iterate through vectgor
std::vector<int> vec_of_ints(10, 1); // 10 ints all with value 1
for (int i : vec_of_ints) { // use auto for more complex types
std::cout << vec_of_ints.at(i) << " ";
}
std::cout << std::endl;
how to iterate trough a vector in c++
vector<int> myVector;
myVector.push_back(1);
myVector.push_back(2);
myVector.push_back(3);
myVector.push_back(4);
for(auto x: myVector){
cout<< x << " ";
}
vector<pair<int,int>> myVectorOfPairs;
myVectorOfPairs.push_back({1,2});
myVectorOfPairs.push_back({3,4});
myVectorOfPairs.push_back({5,6});
myVectorOfPairs.push_back({7,8});
for(auto x: myVectorOfPairs){
cout<< x.first << " " << x.second << endl;
}
c++ iterate over vector
for(auto const& value: a) {
/* std::cout << value; ... */
}
iterate over vector in c++
for (auto & element : vector) {
element.doSomething ();
}
c++ looping through a vector
vector<int> vi;
...
for(int i : vi)
cout << "i = " << i << endl;
c++ looping through a vector
for(std::vector<T>::size_type i = 0; i != v.size(); i++) {
v[i].doSomething();
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us