fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::string f(std::string *p) {
  5. return *p;
  6. }
  7.  
  8. int main() {
  9. std::string s[] = {std::string("abc"), std::string("def"), std::string("xyz") };
  10.  
  11. std::vector<std::string *> a;
  12. for (int i = 0; i < 3; i++)
  13. a.push_back(&s[i]);
  14.  
  15. std::vector<std::string *>::iterator p;
  16. std::vector<std::string *> *list;
  17.  
  18. list = &a;
  19. std::cout << "a.size() = " << a.size() << std::endl;
  20. for (unsigned int i = 0; i < a.size(); i++) {
  21. std::cout << "i = " << i << " : " << *a.at(i) << std::endl;
  22. std::cout << f((*list)[i]) << std::endl;
  23. std::cout << f((*list).at(i)) << std::endl;
  24. std::cout << f(list->at(i)) << std::endl;
  25. // std::cout << f(list->at[i]) << std::endl;
  26. p++;
  27. }
  28. return 0;
  29. }
  30. /* end */
Success #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
a.size() = 3
i = 0 : abc
abc
abc
abc
i = 1 : def
def
def
def
i = 2 : xyz
xyz
xyz
xyz