Printing Tuple!(...)[] using for loop?
Kirill
kirill.saidov at mail.com
Fri Jul 2 04:21:24 UTC 2021
I have a `Tuple!(string, ..., string)[] data` that I would like
to print out:
`a b c`
`1 2 3`
`4 5 6`
Furthermore, I want to be able to print any N rows and M
columns of that table. For instance:
`b c`
`2 3`
or
`1 2 3`
`4 5 6`
I am using for loops for that:
// inside some function(rows, cols):
immutable startFromRow = ...;
immutable endWithRow = ...;
immutable startFromCol = ...;
immutable endWithCol = ...;
// print data
for(size_t i = startFromRow; i < endWithRow; i++) {
for(size_t j = startFromCol; j < endWithCol; j++) {
writef("%s", data[i][j]);
}
writef("\n");
}
And the compiler puts out the following:
`Error: variable 'j' cannot be read at compile time`
I tried `data[i].expand[j]`, but the same error occurs anyway.
I have two questions:
1. How do I print the contents of a Tuple using for loops? Or any
other method?
2. What am I missing? How does it actually work under the hood?
Thanks in advance. Any help is greatly appreciated.
More information about the Digitalmars-d-learn
mailing list