fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. struct Point
  6. {
  7. float x, y, z;
  8. };
  9. std::istream& operator>>(std::istream& in, Point& obj)
  10. {return in >> obj.x >> obj.y >> obj.z;}
  11. std::ostream& operator<<(std::ostream& in, const Point& obj)
  12. {return in << obj.x << ' ' << obj.y << ' ' << obj.z;}
  13.  
  14. typedef std::vector<std::vector<Point> > NFPAGE;
  15.  
  16. std::istream& operator>>(std::istream& filestream , NFPAGE& NFPoints) {
  17. long numpoints = 0;
  18. while(filestream) {
  19. filestream >> numpoints;
  20. if (!filestream)
  21. break;
  22. std::vector<Point> pnts(numpoints);
  23. for(int i=0; filestream && i<numpoints; ++i)
  24. filestream >> pnts[i];
  25. if (filestream)
  26. NFPoints.emplace_back(std::move(pnts));
  27. }
  28. return filestream;
  29. }
  30.  
  31. std::ostream& operator<<(std::ostream& filestream, const NFPAGE& NFPoints) {
  32. filestream << NFPoints.size() << '\n';
  33. for(unsigned i=0; i<NFPoints.size(); ++i) {
  34. filestream << NFPoints[i].size() << '\n';
  35. for(unsigned j=0; j<NFPoints[i].size(); ++j)
  36. filestream << NFPoints[i][j] << '\n';
  37. }
  38. return filestream;
  39. }
  40.  
  41. int main()
  42. {
  43. NFPAGE NFPoints;
  44. //std::ifstream filestream("Some file");
  45. //filestream >> NFPoints;
  46. std::cin >> NFPoints;
  47. std::cout << NFPoints;
  48. }
Success #stdin #stdout 0s 3068KB
stdin
3 
-0.16 -0.025 0.18 
-0.1575 -0.025 0.18 
-0.155 -0.025 0.18 
3 
-0.1525 -0.025 0.18 
-0.15 -0.025 0.18 
-0.1475 -0.025 0.18
stdout
2
3
-0.16 -0.025 0.18
-0.1575 -0.025 0.18
-0.155 -0.025 0.18
3
-0.1525 -0.025 0.18
-0.15 -0.025 0.18
-0.1475 -0.025 0.18