fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. void read3floats(std::istream & i, std::string const & sw)
  5. {
  6. float a, b, c;
  7. i >> a >> b >> c;
  8. std::cout << sw << " - read " << a << ", " << b << ", " << c << std::endl;
  9. }
  10.  
  11. int main()
  12. {
  13. std::string buf = "\
  14. # 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware\n\
  15. # File Created: 27.02.2012 19:39:59\n\
  16. \n\
  17. mtllib level.mtl\n\
  18. \n\
  19. #\n\
  20. # object Plane001\n\
  21. #\n\
  22. \n\
  23. v -56.7521 0.0000 -8.0054\n\
  24. v -19.4765 0.0000 -8.0054\n\
  25. v -19.4765 0.0000 -35.5556\n\
  26. v -56.7521 0.0000 -35.5556\n\
  27. \n\
  28. vn 0.0000 1.0000 -0.0000\n\
  29. vn -0.0294 0.9987 -0.0424\n\
  30. vn 1.0000 0.0000 -0.0000\n\
  31. vn 0.0000 0.0000 -1.0000\n\
  32. \n\
  33. vt 0.0000 0.6614 0.0000\n\
  34. vt 0.3080 0.6614 0.0000\n\
  35. vt 0.3080 1.0000 0.0000\n\
  36. vt 0.0000 1.0000 0.0000\n\
  37. \n";
  38. std::istringstream iss(buf);
  39.  
  40. while (!iss.eof()) {
  41. std::string sw;
  42. iss >> sw;
  43. if (sw == "v" || sw == "vt") read3floats(iss, sw);
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
v - read -56.7521, 0, -8.0054
v - read -19.4765, 0, -8.0054
v - read -19.4765, 0, -35.5556
v - read -56.7521, 0, -35.5556
vt - read 0, 0.6614, 0
vt - read 0.308, 0.6614, 0
vt - read 0.308, 1, 0
vt - read 0, 1, 0