/* 顶点 */
// 描述
typedef boost::graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
// 迭代器方式一:vp中的一对迭代器分别指向第一个顶点和最后的一个顶点之后
cpp
typedef boost::graph_traits < graph_t >::vertex_iterator viter;
std::pair<viter, viter> vp=vertices(g);
for(viter=vp.first ; viter != vp.second; ++viter)
std::cout << *viter << " ";
// 迭代器方式二
cpp
typedef graph_traits<Graph>::vertex_iterator vertex_iter;
std::pair<vertex_iter, vertex_iter> vp;
for (vp = vertices(g); vp.first != vp.second; ++vp.first)
std::cout << index[*vp.first] << " ";
std::cout << std::endl;
/* 边 */
// 描述
cpp
typedef boost::graph_traits < graph_t >::edge_descriptor edge_descriptor;
// 迭代器方式一: 得到所有边,erange中的一对迭代器分别指向第一条边和最后的一条边之后
cpp
typedef graph_traits<graph_t>::edge_iterator eiter;
std::pair<edge_iter, edge_iter> erange = edges(g);
for(eiter=erange.first; eiter!=erange.second; ++eiter)
cout << source(*eiter,g) << "-->" << target(*eiter,g) << endl;
// 迭代器方式二
cpp
graph_traits<Graph>::edge_iterator ei, ei_end;
for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
std::cout << "(" << index[source(*ei, g)]<< "," << index[target(*ei, g)] << ") ";
cout << endl;
/* 权重 */
cpp
boost::property_map<graph_t, boost::edge_weight_t>::type pmpWeightmap = boost::get(boost::edge_weight, g);
/* 点索引 */
cpp
boost::property_map<graph_t, boost::vertex_index_t>::type pmpIndexmap = boost::get(boost::vertex_index, g);
/* 输出属性 */
cpp
boost::dynamic_properties dp;