Advertisement
wheelsmanx

C++ CleanUp.H

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