Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. void getInput(char * inFile)
  2. {
  3. enum direction_t {NORTH, SOUTH};
  4. direction_t direction;
  5. enum priority_t {HIGH, LOW};
  6. priority_t priority;
  7. string line;
  8. ifstream inFile(inFile);
  9. if(!inFile.good())
  10. {
  11. cerr << "can't open input file";
  12. exit(1);
  13. }
  14. while(getline(inFile, line))
  15. {
  16. char first = line.at(0);//first letter signifies direction and priority
  17. if(first == 'n')
  18. {
  19. direction = NORTH;
  20. priority = LOW;
  21. }
  22. else if(first == 'N')
  23. {
  24. direction = NORTH;
  25. priority = HIGH;
  26. }
  27. else if(first == 's')
  28. {
  29. direction = SOUTH;
  30. priority = LOW;
  31. }
  32. else if(first == 'S')
  33. {
  34. direction = SOUTH;
  35. priority = HIGH;
  36. }
  37. else
  38. {
  39. cerr << "invalid direction given: " << first << endl;
  40. //exit(1);
  41. }
  42. size_t commaIndex = line.find(",", 2);//know first character is letter, second is comma
  43. string firstNumber = line.substr(2, commaIndex-2);
  44. string secondNumber = line.substr(commaIndex+1, line.length());
  45. cout << "firstNumber: " << firstNumber << " secondNumber " << secondNumber << endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement