How to use copy constructor to initialize set from elements of other set in C++

1 Answer

0 votes
#include <iostream>       
#include <set> 
           
void printSet(std::set<int> st) {
    for (auto n: st) {
        std::cout << n << ' ' ; 
    } 
}
    
int main ()
{
    std::set<int> st1 = {6, 3, 8, 2, 9, 5};
    std::set<int> st2(st1);
     
  
    printSet(st2); 
        
    return 0;
} 
       
       
       
/*
run:
       
2 3 5 6 8 9 
    
*/

 



answered Apr 7, 2020 by avibootz
edited Apr 7, 2020 by avibootz

Related questions

1 answer 151 views
1 answer 157 views
157 views asked Mar 23, 2018 by avibootz
1 answer 147 views
...