Advertisement
Guest User

readgr

a guest
Jan 25th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1.  
  2. Graph graph;
  3. std::string line;
  4. std::stringstream iss;
  5. Graph::Position position;
  6. double x, y, z = -1;
  7. while(!std::cin.eof())
  8. {
  9. getline(std::cin, line);
  10. if(line.length() != 0)
  11. {
  12. iss << line;
  13. iss >> x;
  14. iss >> y;
  15. iss >> z;
  16. if(z<0)
  17. {
  18. position.x = x;
  19. position.y = y;
  20. graph.addVertex(position);
  21. }
  22. else
  23. {
  24. graph.addEdge(x, y, z);
  25. }
  26. }
  27. iss.clear();
  28. line = "";
  29. }
  30.  
  31. //-------------------------------------------------------------------------
  32. /*
  33. //int a, b;
  34. //double c;
  35. getline(std::cin, line);
  36. unsigned number_of_spaces;
  37. number_of_spaces = std::count(line.begin(), line.end(), ' ');
  38. while (number_of_spaces == 1)
  39. {
  40. iss << line;
  41. iss >> x;
  42. iss >> y;
  43. position.x = x;
  44. position.y = y;
  45. graph.addVertex(position);
  46. getline(std::cin, line);
  47. number_of_spaces = std::count(line.begin(), line.end(), ' ');
  48. iss.clear();
  49. }
  50. while (std::cin)
  51. {
  52. iss << line;
  53. iss >> a;
  54. iss >> b;
  55. iss >> c;
  56. graph.addEdge(a, b, c);
  57. getline(std::cin, line);
  58. iss.clear();
  59. }
  60. */
  61. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement