How to use a range based for loop in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
 
void printVector(const std::vector<std::string> &vec) {
    for (const auto &s: vec) {
        std::cout << s << " ";
    }
}
 
int main() {
    const std::vector<std::string> vec = {"c++", "c", "c#", "java", "python", "node.js", "php"};
      
    printVector(vec);
}
 
 
 
 
/*
run:
   
c++ c c# java python node.js php 
   
*/

 



answered Dec 7, 2023 by avibootz

Related questions

1 answer 314 views
1 answer 256 views
1 answer 227 views
1 answer 218 views
1 answer 239 views
2 answers 276 views
...