Обратите внимание, что Boost.Graph имеет перегрузки, которые позволяют упростить ответ Тристрама:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <iostream>
int main()
{
struct Vertex { int foo; };
struct Edge { std::string blah; };
using namespace boost;
using graph_t = adjacency_list<listS, vecS, directedS, Vertex, Edge >;
using vertex_t = graph_traits<graph_t>::vertex_descriptor;
using edge_t = graph_traits<graph_t>::edge_descriptor;
//Instantiate a graph
graph_t g;
// Create two vertices in that graph
vertex_t u = boost::add_vertex(Vertex{123}, g);
vertex_t v = boost::add_vertex(Vertex{456}, g);
// Create an edge conecting those two vertices
boost::add_edge(u, v, Edge{"Hello"}, g);
boost::write_graphviz(std::cout, g, [&] (auto& out, auto v) {
out << "[label=\"" << g[v].foo << "\"]";
},
[&] (auto& out, auto e) {
out << "[label=\"" << g[e].blah << "\"]";
});
std::cout << std::flush;
}
Вывод:
digraph G {
0[label="123"];
1[label="456"];
0->1 [label="Hello"];
}