mirror of https://github.com/CGAL/cgal
Use iformat and Input_rep<double> instead of an additional function
This commit is contained in:
parent
36f1514957
commit
f50bbd72c4
|
|
@ -6,6 +6,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <CGAL/Timer.h>
|
#include <CGAL/Timer.h>
|
||||||
|
#include <CGAL/IO/io.h>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -27,7 +28,7 @@ int main(int argc, char* argv[])
|
||||||
std::cerr << "operator"<< std::endl;
|
std::cerr << "operator"<< std::endl;
|
||||||
t.start();
|
t.start();
|
||||||
for(int i=0; i<n; i++){
|
for(int i=0; i<n; i++){
|
||||||
CGAL::extract(std::cin, d);
|
std::cin >> d;
|
||||||
sum+= d;
|
sum+= d;
|
||||||
}
|
}
|
||||||
t.stop();
|
t.stop();
|
||||||
|
|
@ -67,6 +68,16 @@ int main(int argc, char* argv[])
|
||||||
sum+= d;
|
sum+= d;
|
||||||
}
|
}
|
||||||
t.stop();
|
t.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(choice == 4){
|
||||||
|
std::cerr << "iformat"<< std::endl;
|
||||||
|
t.start();
|
||||||
|
for(int i=0; i<n; i++){
|
||||||
|
std::cin >> CGAL::iformat(d);
|
||||||
|
sum+= d;
|
||||||
|
}
|
||||||
|
t.stop();
|
||||||
}
|
}
|
||||||
std::cerr.precision(17);
|
std::cerr.precision(17);
|
||||||
std::cerr << "sum = " << sum << std::endl;
|
std::cerr << "sum = " << sum << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,25 @@ public:
|
||||||
std::istream& operator()( std::istream& in) const { return (in >> t); }
|
std::istream& operator()( std::istream& in) const { return (in >> t); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if defined( _MSC_VER ) && ( _MSC_VER > 1600 ) && (! defined( CGAL_NO_IFORMAT_DOUBLE ))
|
||||||
|
template <>
|
||||||
|
class Input_rep<double> {
|
||||||
|
double& t;
|
||||||
|
public:
|
||||||
|
//! initialize with a reference to \a t.
|
||||||
|
Input_rep( double& tt) : t(tt) {}
|
||||||
|
//! perform the input, calls \c operator\>\> by default.
|
||||||
|
std::istream& operator()( std::istream& is) const
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
is >> s;
|
||||||
|
sscanf(s.c_str(), "%lf", &t);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/*! \relates Input_rep
|
/*! \relates Input_rep
|
||||||
\brief stream input to the \c Input_rep calls its \c operator().
|
\brief stream input to the \c Input_rep calls its \c operator().
|
||||||
*/
|
*/
|
||||||
|
|
@ -168,28 +187,6 @@ bool
|
||||||
is_binary(std::ios& i);
|
is_binary(std::ios& i);
|
||||||
|
|
||||||
|
|
||||||
#ifdef CGAL_GENERIC_EXTRACT
|
|
||||||
template <typename T>
|
|
||||||
inline std::istream& extract(std::istream& is, T &t)
|
|
||||||
{
|
|
||||||
is >> t;
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline std::istream& extract(std::istream& is, double &d)
|
|
||||||
{
|
|
||||||
#if defined( _MSC_VER ) && ( _MSC_VER > 1600 )
|
|
||||||
std::string s;
|
|
||||||
is >> s;
|
|
||||||
sscanf(s.c_str(), "%lf", &d);
|
|
||||||
#else
|
|
||||||
is >> d;
|
|
||||||
#endif
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
template < class T >
|
template < class T >
|
||||||
inline
|
inline
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue