fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void print_str(std::string const * _str, int _flag = 0){
  5. static int count_call = 0;
  6. ++count_call;
  7. int count_print = _flag ? count_call : 1;
  8.  
  9. while(count_print--)
  10. std::cout << *_str << std::endl;
  11. }
  12.  
  13. int main(){
  14. std::string str{"Hello, world!"};
  15.  
  16. print_str(&str);
  17. print_str(&str);
  18. print_str(&str);
  19. std::cout << std::endl;
  20.  
  21. print_str(&str, 1);
  22. std::cout << std::endl;
  23.  
  24. print_str(&str);
  25.  
  26. return (0);
  27. }
  28.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Hello, world!
Hello, world!
Hello, world!

Hello, world!
Hello, world!
Hello, world!
Hello, world!

Hello, world!