Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to use foreach loop equivalent in C++

3 Answers

0 votes
#include <iostream>

int main() 
{ 
    int arr[] = {1, 2, 3, 4, 5, 6};  
    
    for (int n : arr) {
    	std::cout << n << " ";
    }
}



/*
run:
    
1 2 3 4 5 6 	
    
*/

 



answered Jul 12, 2024 by avibootz
0 votes
#include <iostream>
#include <array>

int main() 
{ 
    std::array<std::string, 4> arr = {"c", "c++", "python", "java"};
    
    for (const std::string& str : arr) {
        std::cout << str << " ";
    }
}



/*
run:
    
c c++ python java 	
    
*/

 



answered Jul 12, 2024 by avibootz
0 votes
#include <iostream>
#include <vector>

int main() 
{ 
    std::vector<std::string> vec{"c", "c++", "python", "java", "c#"};
    
    for (auto str: vec) {
        std::cout << str << " ";
    }
}



/*
run:
    
c c++ python java c# 	
    
*/

 



answered Jul 12, 2024 by avibootz

Related questions

1 answer 130 views
130 views asked Mar 6, 2023 by avibootz
1 answer 144 views
144 views asked Mar 30, 2021 by avibootz
1 answer 122 views
1 answer 157 views
157 views asked Dec 2, 2020 by avibootz
2 answers 170 views
170 views asked Nov 25, 2020 by avibootz
1 answer 122 views
122 views asked Aug 7, 2020 by avibootz
1 answer 170 views
...