Answer the question
In order to leave comments, you need to log in
How do I write 1 row of a 2D array into a 1D array?
How do I write 1 row of a 2D array into a 1D array? I have a two-dimensional array and I need to write its first line into a one-dimensional array, but I don't know how?
int const COL = 7;
int const ROW = 6;
int ar[ROW][COL];
int al[4];
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
ar[i][j] = rand() % 100;
cout << ar[i][j] << "\t";
}
cout << endl;
}
Answer the question
In order to leave comments, you need to log in
Do not forget that your arrays are of different sizes, and the whole string from ar will not fit into al.
Try to forget about raw arrays and use containers.
for (int i = 0; i < std::size(al); i++) {
al[i] = ar[0][i];
}
Well, it's written like this:
Translate into Russian, or guess your login / password / database name? :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question