fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <memory>
  4.  
  5. int main()
  6. {
  7. const int COLS = 5 ;
  8. // using row_type = std::string[COLS] ; // ***
  9. typedef std::string row_type[COLS] ; // ***
  10.  
  11. std::size_t rows ;
  12. std::cout << "rows? " ;
  13. std::cin >> rows ;
  14.  
  15. {
  16. row_type* array = new row_type[rows] ;
  17.  
  18. // use array
  19. for( std::size_t i = 0 ; i < rows ; ++i )
  20. for( std::size_t j = 0 ; j < COLS ; ++j )
  21. array[i][j] = "hello" ;
  22.  
  23. for( std::size_t i = 0 ; i < rows ; ++i )
  24. {
  25. for( std::size_t j = 0 ; j < COLS ; ++j )
  26. std::cout << array[i][j] << ' ' ;
  27. std::cout << '\n' ;
  28. }
  29.  
  30. delete[] array ;
  31. }
  32. }
  33.  
Success #stdin #stdout 0s 2864KB
stdin
6
stdout
rows? hello hello hello hello hello 
hello hello hello hello hello 
hello hello hello hello hello 
hello hello hello hello hello 
hello hello hello hello hello 
hello hello hello hello hello