Advertisement
carmenlouiseb

Untitled

Jul 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. float NGLScene::readStartPos()
  3. {
  4.  
  5. stringFromFile("configFile.txt");
  6. getValues(myFileContents);
  7.  
  8. for(int i=0; i < 2;)
  9. {
  10. float x = retVec.pop_back();
  11. std::cout<<x;
  12. }
  13.  
  14. }
  15.  
  16. //A function to get the contents of a file as a string
  17. std::string stringFromFile(std::string _filename)
  18. {
  19. std::ifstream myFile(_filename);
  20. std::string myFileContents((std::istreambuf_iterator<char>(myFile)), std::istreambuf_iterator<char>());
  21. std::cout<<"hello";
  22. return myFileContents;
  23. }
  24.  
  25. //Using:
  26. //http://www.cplusplus.com/reference/string/string/substr/
  27. //http://www.cplusplus.com/reference/string/string/find/
  28. std::vector<float> getValues(std::string _stringIn)
  29. {
  30. std::vector<float> retVec;
  31. int startPos = 0;
  32. for(int i = 1; i < 3; i++)
  33. {
  34. std::size_t delimPos = _stringIn.find(";", startPos);//Assuming that ';' is your delimiting character
  35. std::size_t lineEndPos = _stringIn.find("\n", startPos);//Should work, not sure
  36. retVec.push_back(std::stof(_stringIn.substr(delimPos, lineEndPos)));
  37. startPos = lineEndPos;
  38. }
  39. return retVec;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement