wheelsmanx

AOC DAY 1 PART 1 cleanUp.h

May 8th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1.  
  2. #pragma once
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6. #include <fstream>
  7. #include <sstream>
  8.  
  9. using namespace std;
  10.  
  11. vector <int> String2Int(vector <string> tempVector) {
  12. stringstream tempSS;
  13. vector <int> tempIntVector;
  14. int tempInt;
  15. for (int i = 0; i < tempVector.size(); i++) {
  16. tempSS << tempVector.at(i);
  17. tempSS >> tempInt;
  18. tempIntVector.push_back(tempInt);
  19. }
  20. return tempIntVector;
  21. }
  22.  
  23. int String2Int(string userInput) {
  24. stringstream tempSS;
  25. int tempInt;
  26. tempSS << userInput;
  27. tempSS >> tempInt;
  28. return tempInt;
  29. }
  30.  
  31. vector <string> cstringsplit(string input, string delimeter) {
  32. int delimSize = delimeter.length();
  33. int inputSize = input.length();
  34. string buffer;
  35. vector <string> v;
  36. for (int i = 0; i < inputSize; i++) {
  37. if (input.substr(i, delimSize) != delimeter) {
  38. buffer += input[i];
  39. }
  40. else {
  41. v.push_back(buffer);
  42. buffer = "";
  43. i = i + delimSize - 1;
  44. }
  45. }
  46. v.push_back(buffer);
  47. buffer = "";
  48. return v;
  49. }
  50.  
  51. vector<string> getInputFile(string location) {
  52. // good example getFile("C:\\temp\\New Text Document.txt");
  53. ifstream fileInput;
  54. vector<string> tempVector;
  55. string tempString;
  56. fileInput.open(location);
  57. while (!fileInput.eof())
  58. {
  59. getline(fileInput, tempString);
  60. tempVector.push_back(tempString);
  61. tempString = " ";
  62. }
  63. return tempVector;
  64. }
  65.  
  66. void vout(vector<string> temp) { for (string c : temp) { cout << c << endl; } }
  67. void vout(vector<int> temp) { for (int c : temp) { cout << c << endl; } }
  68. void vout(vector<bool> temp) { for (bool c : temp) { cout << c << endl; } }
Advertisement
Add Comment
Please, Sign In to add comment