wheelsmanx

CPS 272 Machine Problem 4 Cleanup.h

Nov 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <stdlib.h>
  8. #include <map>
  9. #include <set>
  10.  
  11. using namespace std;
  12. /*
  13. vout(vector<string/int/char>);
  14. // just std::cout << string/int/char << endl;
  15. test();
  16. // this just std outputs "this is a test"
  17. getInputFile("locationoftextFile");
  18. // this returns vector of strings of text file
  19. String2Int(string);
  20. // converts string to int
  21. Int2String(int);
  22. //converts int to string
  23. cStringSplit(string input, string delimiter);
  24. // returns vector of strings separated by the delimiter
  25.  
  26. */
  27.  
  28.  
  29. vector<string> returnMapKeyString(map<string, string> userInput) {
  30. vector<string> returnObject;
  31. for (auto element : userInput) {
  32. returnObject.push_back(element.first);
  33. }
  34. return returnObject;
  35. }
  36. vector<string> returnMapValueString(map<string, string> userInput) {
  37. vector<string> returnObject;
  38. for (auto element : userInput) {
  39. returnObject.push_back(element.second);
  40. }
  41. return returnObject;
  42. }
  43.  
  44. vector<int> returnMapKeyInt(map<int, int> userInput) {
  45. vector<int> returnObject;
  46. for (auto element : userInput) {
  47. returnObject.push_back(element.first);
  48. }
  49. return returnObject;
  50. }
  51. vector<int> returnMapValueInt(map<int, int> userInput) {
  52. vector<int> returnObject;
  53. for (auto element : userInput) {
  54. returnObject.push_back(element.second);
  55. }
  56. return returnObject;
  57. }
  58.  
  59. void readStringMap(map<string, string> userInput) {
  60. cout << endl;
  61. for (auto element : userInput) {
  62. cout << element.first << " <= " << element.second << endl;
  63. }
  64. cout << endl;
  65. }
  66.  
  67. void readIntMap(map<int, int> userInput) {
  68. cout << endl;
  69. for (auto element : userInput) {
  70. cout << element.first << " <= " << element.second << endl;
  71. }
  72. cout << endl;
  73. }
  74.  
  75. vector <int> String2Int(vector <string> tempVector) {
  76. stringstream tempSS;
  77. vector <int> tempIntVector;
  78. int tempInt;
  79. for (int i = 0; i < tempVector.size(); i++) {
  80. tempSS << tempVector.at(i);
  81. tempSS >> tempInt;
  82. tempIntVector.push_back(tempInt);
  83. }
  84. return tempIntVector;
  85. }
  86.  
  87. int String2IntSingle(string userInput) {
  88. stringstream tempSS;
  89. int tempInt;
  90. tempSS << userInput;
  91. tempSS >> tempInt;
  92. return tempInt;
  93. }
  94.  
  95. vector <string> cStringSplit(string input, string delimeter) {
  96. int delimSize = delimeter.length();
  97. int inputSize = input.length();
  98. string buffer;
  99. vector <string> v;
  100. for (int i = 0; i < inputSize; i++) {
  101. if (input.substr(i, delimSize) != delimeter) {
  102. buffer += input[i];
  103. }
  104. else {
  105. v.push_back(buffer);
  106. buffer = "";
  107. i = i + delimSize - 1;
  108. }
  109. }
  110. v.push_back(buffer);
  111. buffer = "";
  112. return v;
  113. }
  114.  
  115. vector<string> getInputFile(string location) {
  116. // good example getFile("C:\\temp\\New Text Document.txt");
  117. ifstream fileInput;
  118. vector<string> tempVector;
  119. string tempString;
  120. fileInput.open(location);
  121. while (!fileInput.eof())
  122. {
  123. getline(fileInput, tempString);
  124. tempVector.push_back(tempString);
  125. tempString = " ";
  126. }
  127. return tempVector;
  128. }
  129. void test() {
  130. cout << "TEST" << endl;
  131. }
  132.  
  133. void vout(vector<string> temp) { for (string c : temp) { cout << c << endl; } }
  134. void vout(vector<int> temp) { for (int c : temp) { cout << c << endl; } }
  135. void vout(vector<bool> temp) { for (bool c : temp) { cout << c << endl; } }
Advertisement
Add Comment
Please, Sign In to add comment