gpt4 book ai didi

c++ - 使 boost 工作(visual studio 2010 windows 2007)

转载 作者:搜寻专家 更新时间:2023-10-31 02:22:59 25 4
gpt4 key购买 nike

我正在尝试在 Windows 7 上的 visual studio 2010 上使用 boost。我在这里遵循了这个很好的解释- link .但没有成功。

我遇到了很多错误:

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;
}

我很乐意提供一些帮助,谢谢。

最佳答案

您缺少几个 usings 或 namespace 声明。还缺少:#include <iostream>

我建议 using namespace booststd::资格:

Live On Coliru

#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;
}

关于c++ - 使 boost 工作(visual studio 2010 windows 2007),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29729631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com