我试图在Windows 7的Visual Studio 2010上使用boost。我遵循此链接的解释。但没有成功。
我收到很多错误:
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(20): error C2143: syntax error : missing ';' before '<'
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(22): error C2065: 'Graph' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(22): error C2146: syntax error : missing ';' before identifier 'G'
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(22): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(23): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(23): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(24): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(24): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(25): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(25): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(26): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(26): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(28): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(28): error C3861: 'num_vertices': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(29): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(29): error C3861: 'connected_components': identifier not found
这是我试图构建的代码示例:
#include <algorithm>
#include <utility>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
void main()
{
typedef adjacency_list <vecS, vecS, undirectedS> Graph;
Graph G;
add_edge(0, 1, G);
add_edge(1, 4, G);
add_edge(4, 0, G);
add_edge(2, 5, G);
std::vector<int> component(num_vertices(G));
int num = connected_components(G, &component[0]);
std::vector<int>::size_type i;
cout << "Total number of components: " << num << endl;
for (i = 0; i != component.size(); ++i)
cout << "Vertex " << i <<" is in component " << component[i] << endl;
cout << endl;
}
谢谢您,我会很高兴。
您缺少几个uses或名称空间声明。还缺少:#include <iostream>
我建议using namespace boost
和std::
资格:
#include <algorithm>
#include <utility>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <iostream>
using namespace boost;
int main()
{
typedef adjacency_list <vecS, vecS, undirectedS> Graph;
Graph G;
add_edge(0, 1, G);
add_edge(1, 4, G);
add_edge(4, 0, G);
add_edge(2, 5, G);
std::vector<int> component(num_vertices(G));
int num = connected_components(G, &component[0]);
std::vector<int>::size_type i;
std::cout << "Total number of components: " << num << std::endl;
for (i = 0; i != component.size(); ++i)
std::cout << "Vertex " << i <<" is in component " << component[i] << std::endl;
std::cout << std::endl;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句