Read into APMatrix

My question is, how do you read data (just a bunch of ints) from a file into an AP matrix from the “APMatrix” class.
It depends entirely on your input. What have you got?
Well so far all I’m trying to do is read a data file full of ints into an APMatrix. That’s the first step and I’m stuck. I initialized the matrix with the number of rows and columns (because for this assignment we already know the numbers) and I’m trying to read data from the file into the matrix. I’m supposed to read the numbers into the matrix in “row major order” idk what that means.
Last edited on
Hint: when asked for more information, don’t just repeat yourself.

“data (just a bunch of ints) from a file”
“a data file full of ints”

So... there is absolutely NO formatting on the data, AND you already know the target matrix size?

“because for this assignment we already know” → “the number of rows and columns”

It sounds like all you need is a nested loop to index over your matrix: outer loop is for rows, inner loop is for columns. Each time you get a new int, put it in the matrix at the current row and column indices.
Well that’s all there is to my question honestly like why does it matter what’s in the file other than literally it’s just numbers. 1878 6758. Just numbers. I appreciate your reply I’m still lost tho.

1
2
3
4
5
6
7
8
9
ifstream dataFile (“data.txt”);
apmatrix<int> matrix(500, 900); 

for (int i = 0; i <= 500; i++){
      // what goes in loop?
     for( int j = 0; j <= 900; j++) {
      //here too 
     } 
} 


EDIT: I FIGURED IT OUT.

This is what my code ended up looking like for the for loops
1
2
3
4
for (int i = 0; i < 500; i++){
     for( int j = 0; j < 900; j++) {
      dataFile >> matrix[i][j]; 
     } 
Last edited on
Well, I’m glad you got it figured out.

idk6199 wrote:
Well that’s all there is to my question honestly like why does it matter what’s in the file...

With that kind of attitude and thinking, you won’t last long in computer science.

¿Te importaría si te hablaba en español?

Nó cad a tharlódh dá scríobhfainn i nGaeilge?

Input matters very much, and getting huffy when you are questioned to provide a simple piece of extra detail is a really good way to turn away knowledgeable people who would otherwise desire nothing more than to help you along.
With that kind of attitude and thinking, you won’t last long in computer science.
A very generous career outlook given the purpose of first interviews.
Topic archived. No new replies allowed.