fork download
  1. #include <string>
  2. #include <iostream>
  3. std::string repeat( const std::string &word, int times ) {
  4. std::string result ;
  5. result.reserve(times*word.length()); // avoid repeated reallocation
  6. for ( int a = 0 ; a < times ; a++ )
  7. result += word ;
  8. return result ;
  9. }
  10.  
  11. int main( ) {
  12. std::cout << repeat( "Ha" , 5 ) << std::endl ;
  13. return 0 ;
  14. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
HaHaHaHaHa