简体   繁体   中英

istream_iterator for CGAL

I am embarrased to ask, but I haven't used CGAL for a while. I am trying to make Convex_hull_2/convex_hull_yz.cpp example of CGAL get the input from a file, rather than from redirection via cmd, like ./convex_hull_yz < convex_hull_yz.cin . Here is the code:

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

And here is the ref . So obviously my attempt wouldn't work:

/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" );

Relevant question: Is there a C++ iterator that can iterate over a file line by line? , which I understand, but I fail to connect with CGAL. Any ideas please?

You can use the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM