【发布时间】:2020-02-16 16:03:22
【问题描述】:
我正在学习 boost::graph 并尝试将 name 属性添加到 Vertex。但是,在这样做之后,write_graphviz 不会保存任何内容(没有此属性,它可以工作)。
头文件:
struct VertexProps
{
std::string name;
};
struct EdgeProps
{
double weight;
};
using Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, VertexProps, EdgeProps>;
using Vertex = boost::adjacency_list<>::vertex_descriptor;
using Edge = std::pair<boost::adjacency_list<>::edge_descriptor, bool>;
using EdgeList = std::pair<boost::adjacency_list<>::edge_iterator,
boost::adjacency_list<>::edge_iterator>;
Cpp 文件:
Vertex vertex = boost::add_vertex({std::move(vertexName)}, g);
std::filebuf fb;
fb.open("output.txt", std::ios::out);
std::ostream os(&fb);
write_graphviz(os, g, boost::make_label_writer(get(&VertexProps::name, g)), boost::make_label_writer(get(&EdgeProps::weight, g)));
fb.close();
该文件应该包含图表,但我只能看到:
digraph G {
}
【问题讨论】:
标签: c++ boost boost-graph