#include <iostream>
#include <string>
#include <memory>
int main()
{
const int COLS = 5 ;
using row_type = std::string[COLS] ;
std::size_t rows ;
std::cout << "rows? " ;
std::cin >> rows ;
{
row_type* array = new row_type[rows] ;
// use array
for( std::size_t i = 0 ; i < rows ; ++i )
for( std::size_t j = 0 ; j < COLS ; ++j )
array[i][j] = "hello" ;
for( std::size_t i = 0 ; i < rows ; ++i )
{
for( std::size_t j = 0 ; j < COLS ; ++j )
std::cout << array[i][j] << ' ' ;
std::cout << '\n' ;
}
delete[] array ;
}
// better
{
std::unique_ptr< row_type[] > array( new row_type[rows] ) ;
// use array
for( std::size_t i = 0 ; i < rows ; ++i )
for( std::size_t j = 0 ; j < COLS ; ++j )
array[i][j] = "bonjour" ;
for( std::size_t i = 0 ; i < rows ; ++i )
{
for( std::size_t j = 0 ; j < COLS ; ++j )
std::cout << array[i][j] << ' ' ;
std::cout << '\n' ;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8bWVtb3J5PgoKaW50IG1haW4oKQp7CiAgICBjb25zdCBpbnQgQ09MUyA9IDUgOwogICAgdXNpbmcgcm93X3R5cGUgPSBzdGQ6OnN0cmluZ1tDT0xTXSA7CgogICAgc3RkOjpzaXplX3Qgcm93cyA7CiAgICBzdGQ6OmNvdXQgPDwgInJvd3M/ICIgOwogICAgc3RkOjpjaW4gPj4gcm93cyA7CgogICAgewogICAgICAgIHJvd190eXBlKiBhcnJheSA9IG5ldyByb3dfdHlwZVtyb3dzXSA7CgogICAgICAgIC8vIHVzZSBhcnJheQogICAgICAgIGZvciggc3RkOjpzaXplX3QgaSA9IDAgOyBpIDwgcm93cyA7ICsraSApCiAgICAgICAgICAgIGZvciggc3RkOjpzaXplX3QgaiA9IDAgOyBqIDwgQ09MUyA7ICsraiApCiAgICAgICAgICAgICAgICBhcnJheVtpXVtqXSA9ICJoZWxsbyIgOwoKICAgICAgICBmb3IoIHN0ZDo6c2l6ZV90IGkgPSAwIDsgaSA8IHJvd3MgOyArK2kgKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKCBzdGQ6OnNpemVfdCBqID0gMCA7IGogPCBDT0xTIDsgKytqICkKICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCBhcnJheVtpXVtqXSA8PCAnICcgOwogICAgICAgICAgICBzdGQ6OmNvdXQgPDwgJ1xuJyA7CiAgICAgICAgfQoKICAgICAgICBkZWxldGVbXSBhcnJheSA7CiAgICB9CgogICAgLy8gYmV0dGVyCiAgICB7CiAgICAgICAgc3RkOjp1bmlxdWVfcHRyPCByb3dfdHlwZVtdID4gYXJyYXkoIG5ldyByb3dfdHlwZVtyb3dzXSApIDsKCiAgICAgICAgLy8gdXNlIGFycmF5CiAgICAgICAgZm9yKCBzdGQ6OnNpemVfdCBpID0gMCA7IGkgPCByb3dzIDsgKytpICkKICAgICAgICAgICAgZm9yKCBzdGQ6OnNpemVfdCBqID0gMCA7IGogPCBDT0xTIDsgKytqICkKICAgICAgICAgICAgICAgIGFycmF5W2ldW2pdID0gImJvbmpvdXIiIDsKCiAgICAgICAgZm9yKCBzdGQ6OnNpemVfdCBpID0gMCA7IGkgPCByb3dzIDsgKytpICkKICAgICAgICB7CiAgICAgICAgICAgIGZvciggc3RkOjpzaXplX3QgaiA9IDAgOyBqIDwgQ09MUyA7ICsraiApCiAgICAgICAgICAgICAgICBzdGQ6OmNvdXQgPDwgYXJyYXlbaV1bal0gPDwgJyAnIDsKICAgICAgICAgICAgc3RkOjpjb3V0IDw8ICdcbicgOwogICAgICAgIH0KICAgIH0KfQo=