我很尴尬地问,但我暂时没有使用过CGAL。我试图让Convex_hull_2/convex_hull_yz.cpp CGAL的示例从文件中获取输入,而不是通过cmd重定向,如 X1 X2 AUC_1 AUC_2 ratio Country Comp
1 Porsche_1 Astra_3 5860133.702 4.849720e+06 1.2083447 France 0
2 Mazda_2 Astra_4 1296009.939 9.289805e+05 1.3950885 France 1
3 Tico_1 Mercedes_1 333123.493 3.205476e+05 1.0392325 Germany 1
4 Nexia_1 BMW_1 250348.941 2.232872e+05 1.1211970 Italy 0
5 Astra_1 BMW_2 1376193.334 1.340641e+06 1.0265187 Poland 0
6 Astra_2 Porsche_1 4080502.863 4.720330e+06 0.8644529 Poland 1
7 Astra_3 Mazda_2 3777603.233 4.369150e+06 0.8646082 Poland 0
8 Astra_4 Tico_1 3503973.487 3.371021e+06 1.0394398 Poland 1
9 Mercedes_1 Nexia_1 99101538.620 1.085913e+08 0.9126107 Norway 1
10 BMW_1 Audi_1 231873.846 2.664898e+05 0.8701041 Sweden 0
。这是代码:
./convex_hull_yz < convex_hull_yz.cin
这是ref。显然,我的尝试不起作用:
#include <iostream>
#include <iterator>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Projection_traits_yz_3.h>
#include <CGAL/convex_hull_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K3;
typedef CGAL::Projection_traits_yz_3<K3> K;
typedef K::Point_2 Point_2;
int main()
{
std::istream_iterator< Point_2 > input_begin( std::cin );
std::istream_iterator< Point_2 > input_end;
std::ostream_iterator< Point_2 > output( std::cout, "\n" );
CGAL::convex_hull_2( input_begin, input_end, output, K() );
return 0;
}
相关问题:Is there a C++ iterator that can iterate over a file line by line?,据我所知,但我未能与CGAL联系。有什么想法吗?
答案 0 :(得分:2)
您可以使用以下内容:
std::ifstream input("input.cin");
std::istream_iterator< Point_2 > input_begin( input );