cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
2D vector representation of adjacency li
2D vector representation of adjacency list
Feb 16, 2010 at 5:41pm UTC
jasonSung
(14)
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?
Feb 16, 2010 at 5:59pm UTC
hamsterman
(4538)
you could read each line with getline() and then extract each number usimg stringstream.
Last edited on
Feb 16, 2010 at 5:59pm UTC
Feb 16, 2010 at 6:05pm UTC
jasonSung
(14)
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!!
Feb 16, 2010 at 6:15pm UTC
hamsterman
(4538)
1
2
3
4
string str; getline(myfile, str); stringstream sstream(str); sstream >> my_int;
Feb 16, 2010 at 7:10pm UTC
Duthomhas
(13282)
Google around "vector matrix class c++" for more.
Topic archived. No new replies allowed.