2D vector representation of adjacency list

I have an input text file test.txt which contains adjacency list.

test.txt
0 0 1 4
0 0 0 2 3
0 0 1 3
0 0 1 2 4
0 0 0 3

I would like to read this input file and store it in 2D vector.

I have no idea how to approach.

I think I can read the file first and count the number of rows. Then read the file one more time and store the data to vector. Is this a good approach?
you could read each line with getline() and then extract each number usimg stringstream.
Last edited on
would you give me an idea how to use stringstrem?

i have a book Ivo Horton's beginning visual c++ 2008 but there is nothing like stringstream.

Thank you for quick response!!
1
2
3
4
string str;
getline(myfile, str);
stringstream sstream(str);
sstream >> my_int;
Google around "vector matrix class c++" for more.
Topic archived. No new replies allowed.