Reading a matrix file and storing it in array

P

pariub

So here is my problem once... i have a file called
network.txt ...its a 13X13 matrix...but the network.txt can go up to
100X 100.
I should read the text file and store it in array [j][k].

0110000000000
0001000000000
0001000000000
0000110000000
0000001000000
0000001000000
0000000100000
0000000010000
0000000001000
0000000000110
0000000000001
0000000000001
0000000000000

I struggled doing it in C...can somebody help with this in C++
 
D

Daniel T.

So here is my problem once... i have a file called
network.txt ...its a 13X13 matrix...but the network.txt can go up to
100X 100.
I should read the text file and store it in array [j][k].

0110000000000
0001000000000
0001000000000
0000110000000
0000001000000
0000001000000
0000000100000
0000000010000
0000000001000
0000000000110
0000000000001
0000000000001
0000000000000

I struggled doing it in C...can somebody help with this in C++

You should not store it in a "array[j][k]" is the answer. Unless, of
course, it's a homework assignment and the teacher says you must... Is
that the case?
 
J

Jakob Bieling

So here is my problem once... i have a file called
network.txt ...its a 13X13 matrix...but the network.txt can go up to
100X 100.
I should read the text file and store it in array [j][k].

0110000000000
0001000000000
0001000000000
0000110000000
0000001000000
0000001000000
0000000100000
0000000010000
0000000001000
0000000000110
0000000000001
0000000000001
0000000000000

I struggled doing it in C...can somebody help with this in C++

I do not know what actual problem you are to solve .. but how about
you read every line into a string and store those in a vector? So you
are left with:

std::vector <std::string> matrix;

and you can access it like:

matrix [0] [1];

to get the second character of the first line (a '1' in your
example).

hth
 
D

Default User

So here is my problem once... i have a file called
network.txt ...its a 13X13 matrix...but the network.txt can go up to
100X 100.
I should read the text file and store it in array [j][k].

What have you tried so far?


It's probably easier to use nested vectors versus that array, unless
you have some other reason. Unfortunately, you've given us virtually no
information about the actual problem you're trying to solve. What is
the purpose of the matrix? How will it be used after you create it?
These are important design questions that must be dealt with before any
implementation.




Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top