2016-04-14 4 views
0

Je suis embarrassé de demander, mais je n'ai pas utilisé CGAL depuis un moment. J'essaie de faire Convex_hull_2/convex_hull_yz.cpp exemple de CGAL obtenir l'entrée d'un fichier, plutôt que de la redirection via cmd, comme ./convex_hull_yz < convex_hull_yz.cin. Voici le code:istream_iterator pour CGAL

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

Et voici le ref. Alors, évidemment, ma tentative ne fonctionnerait pas:

/home/gsamaras/CGAL-4.7/examples/Convex_hull_2/convex_hull_yz.cpp:13:83: error: no matching function for call to ‘std::istream_iterator<CGAL::Point_3<CGAL::Epick> >::istream_iterator(const char [19])’ 
    std::istream_iterator<Point_2> input_begin("convex_hull_yz.cin"); 

question pertinente: Is there a C++ iterator that can iterate over a file line by line?, que je comprends, mais je ne vous connecter avec CGAL. Des idées s'il vous plaît?

+0

Je suppose que l'entrée 'std :: ifstream ("input.cin"); std :: istream_iterator < Point_2 > input_begin (entrée); 'devrait fonctionner – sloriot

Répondre

2

Vous pouvez utiliser les éléments suivants:

std::ifstream input("input.cin"); 
std::istream_iterator<Point_2> input_begin(input);