Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. 10
  2. 0.000 0.010
  3. 0.000 0.260
  4. 0.000 0.510
  5. 0.000 0.760
  6. 0.000 1.010
  7. 0.000 1.260
  8. 0.000 1.510
  9. 0.000 1.760
  10. 0.000 2.010
  11. 0.000 2.260
  12. // Blank line here
  13.  
  14. template <typename T>
  15. struct point
  16. {
  17. point (T x = 0, T y = 0) : x (x), y (y) {}
  18.  
  19. T x ;
  20. T y ;
  21.  
  22. friend std::istream& operator>> (std::istream &is, point &p) {
  23. is >> p.x >> p.y ;
  24. return is ;
  25. }
  26. };
  27.  
  28. int main (void)
  29. {
  30. std::string strFile = "Points.txt" ;
  31.  
  32. std::ifstream file ;
  33. file.exceptions (std::ios::failbit | std::ios::badbit) ;
  34. std::vector <point <double> > vec ;
  35.  
  36. try {
  37. file.open (strFile) ;
  38.  
  39. int nPoints = 0 ;
  40. file >> nPoints ;
  41.  
  42. for (int n = 0; n < nPoints; ++n) {
  43. point <double> p ;
  44. file >> p ;
  45. vec.push_back (p) ;
  46. }
  47. }
  48.  
  49. catch (std::ios_base::failure &e) {
  50. std::cerr << e.what () << "n" ;
  51. return 1 ;
  52. }
  53.  
  54. return 0 ;
  55. }
  56.  
  57. int main (void)
  58. {
  59. std::string strFile = "Points.txt" ;
  60.  
  61. std::ifstream file ;
  62. file.exceptions (std::ios::failbit | std::ios::badbit) ;
  63. std::vector <point <double> > vec ;
  64.  
  65. try {
  66. file.open (strFile) ;
  67.  
  68. int nPoints = 0 ;
  69. file >> nPoints ;
  70.  
  71. std::copy (
  72. std::istream_iterator <point <double> > (file),
  73. std::istream_iterator <point <double> > (),
  74. std::back_inserter (vec)
  75. ) ;
  76. }
  77.  
  78. catch (std::ios_base::failure &e) {
  79. std::cerr << e.what () << "n" ;
  80. return 1 ;
  81. }
  82.  
  83. return 0 ;
  84. }
  85.  
  86. std::copy (
  87. std::istream_iterator <point <double> > (file),
  88. std::istream_iterator <point <double> > (),
  89. std::back_inserter (vec)
  90. ) ;
  91.  
  92. std::copy_n (
  93. std::istream_iterator <point <double> > (file),
  94. nPoints,
  95. std::back_inserter (vec)
  96. ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement