fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. class Collector {
  6. public:
  7. void push(const std::string& s) {
  8. data_.push_back(s);
  9. }
  10.  
  11. ~Collector() {
  12. for (const auto& s: data_) {
  13. std::cout << "(" << s << ")" << std::endl;
  14. }
  15. std::reverse(data_.begin(), data_.end());
  16. for (const auto& s: data_) {
  17. std::cout << "[" << s << "]" << std::endl;
  18. }
  19. }
  20. private:
  21. std::vector<std::string> data_;
  22. };
  23.  
  24. void func(const std::string& s) {
  25. static Collector collector;
  26. collector.push(s);
  27. }
  28.  
  29. int main() {
  30. func("1");
  31. func("2");
  32. func("qwer");
  33. }
  34.  
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
(1)
(2)
(qwer)
[qwer]
[2]
[1]