fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <initializer_list>
  5.  
  6. std::vector<int> *createvec(std::initializer_list<int> il){
  7. std::vector<int> *pv = new std::vector<int>(il); // initialized the
  8. //vector through the initializer list il
  9. return pv;
  10. }
  11.  
  12. void printvec(std::vector<int> *p){
  13. for(auto it = p->begin(); it != p->end(); ++it){
  14. std::cout<<*it<<std::endl;
  15. }
  16. delete p;
  17. }
  18.  
  19. int main(){
  20.  
  21. std::vector<int> *thepointer = createvec({3,5,8,2});
  22. printvec(thepointer);
  23. thepointer = nullptr;
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
3
5
8
2