title: Constructing a Boost graph from a file (Adjacency list)
body: <p>I'm trying to get started with the very good Boost graph library. </p>
  
  <p>The first step is reading a graph from a file, where each line contains edges separated by spaces. </p>
  
  <p>I can't seem to get it done right. My current code looks like this:</p>
  
  <pre><code>..include stuff..
  using namespace boost;
  
  typedef boost::adjacency_list&lt;listS, vecS, undirectedS&gt; Graph;
  
  Graph get_graph(char* str1){
  
    Graph g; 
  
    std::ifstream infile(str1);
    std::string line;
    int e1;
    int e2;
  
    //std::map&lt;int,g&gt; VertexList;
  
    while (std::getline(infile, line)){
  
      std::istringstream iss(line);
  
      //std::cout&lt;&lt;line&lt;&lt;"\n";
  
      std::vector&lt;std::string&gt; strs;
      split(strs, line, is_any_of(" "));
  
  
      //std::cout&lt;&lt;" Adding edge: " &lt;&lt; strs[0]&lt;&lt; " to " &lt;&lt; strs[1] &lt;&lt; "\n";
  
      std::istringstream ss(strs[0].substr(0,5));
      ss &gt;&gt; e1;
  
      std::istringstream s2(strs[1].substr(0,5));
      s2 &gt;&gt; e2;
  
  
      //ADD e1 and e2 to a graph and connect them with an edge somehow!
  
  
  
      //    VertexList[123]=boost::add_vertex(g);
  
      //Graph::vertex_descriptor v2 = boost::add_vertex(g);
  
      //add individual vertices to the graph..
      //e1 = add_vertex(g);
      //e2 = add_vertex(g);
  
      //add the corresponding edge..
  
  
    }
  
    std::cout&lt;&lt;num_vertices(g)&lt;&lt;std::endl;
  
  
  
    return g;
  
  }
  
  int main(int argc, char *argv[]){ 
  
    Graph g = get_graph(argv[1]);
  
  
    //degree_vec(g);
  
    return 0;
  
  }
  </code></pre>
  
  <p>File example:</p>
  
  <pre><code>214328887 34428380
  17116707 28465635
  380580781 18996905
  221036078 153460275
  107830991 17868918
  151338729 222261763
  19705747 34428380
  222261763 88323281
  19933035 149538028
  158419434 17434613
  </code></pre>
  
  <p>Things I tried and kind of worked:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/22569535/using-boost-graph-library-how-to-create-a-graph-by-reading-edge-lists-from-file">Using boost graph library: how to create a graph by reading edge lists from file</a>, but it reads Edge lists, which do not help me as I can not call functions, bound to Adjacency lists (or can I?)</p></li>
  <li><p>Using <code>add_edge(e1,e2,g)</code> did not work, as in this case <code>e1</code> and <code>e2</code> can only be unsigned integers of length 1 (?), It threw some weird results if I used <code>add_edge(123,32,g)</code> for example. (like when I counted vertices, there were 122, instead of 1)</p></li>
  <li><p>Using <code>vertex_descriptors</code>, for e.g. <code>Graph::vertex_descriptor e1 = boost::add_vertex(g);</code> and then adding edges using these descriptors, but I can't seem to make it work (as I said, this is relatively new to me)</p></li>
  </ul>