Advertisement
Guest User

Getting this junk out of my vector

a guest
Feb 26th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. 1
  2. 7
  3. 7
  4. 1
  5.  
  6. dictionary.txt
  7. 1 cute
  8. 2 hello
  9. 3 ugly
  10. 4 easy
  11. 5 difficult
  12. 6 tired
  13. 7 beautiful
  14. synonyms
  15. 1 7
  16. 7 1
  17. antonyms
  18. 1 3
  19. 3 1 7
  20. 4 5
  21. 5 4
  22. 7 3
  23.  
  24. #include <iostream>
  25. #include <fstream>
  26. #include <string>
  27.  
  28. #include <sstream>
  29. #include <vector>
  30.  
  31.  
  32. using namespace std;
  33.  
  34. class WordInfo{
  35. public:
  36. WordInfo(){}
  37. ~WordInfo() {
  38. }
  39.  
  40. int id() const {return myId;}
  41.  
  42. void readWords(istream &in)
  43. {
  44. in>>myId>>word;
  45. }
  46.  
  47. void pushSynonyms (string synline, vector <WordInfo> wordInfoVector)
  48. {
  49. stringstream synstream(synline);
  50. vector<int> synsAux;
  51. int num;
  52. while (synstream >> num) synsAux.push_back(num);
  53. cout<<synsAux.size();
  54.  
  55. for (int i=0; i<synsAux.size(); i++){
  56. cout<<synsAux[i]<<endl;
  57. // THIS LINE SHOULD BE PRINTING
  58. //1
  59. //7
  60. //7
  61. //1
  62. }
  63. }
  64.  
  65. void pushAntonyms (string antline, vector <WordInfo> wordInfoVector)
  66. {
  67.  
  68. }
  69.  
  70. //--dictionary output function
  71. void printWords (ostream &out)
  72. {
  73. out<<myId<< " "<<word;
  74. }
  75.  
  76. //--equals operator for String
  77. bool operator == (const string &aString)const
  78. {
  79. return word ==aString;
  80. }
  81.  
  82. //--less than operator
  83. bool operator <(const WordInfo &otherWordInfo) const
  84. { return word<otherWordInfo.word;}
  85.  
  86. //--more than operator
  87. bool operator > (const WordInfo &otherWordInfo)const
  88. {return word>otherWordInfo.word;}
  89.  
  90. private:
  91. vector <int> mySynonyms;
  92. vector <int> myAntonyms;
  93. string word;
  94. int myId;
  95. };
  96.  
  97. //--Definition of input operator for WordInfo
  98. istream & operator >>(istream &in, WordInfo &word)
  99. {
  100. word.readWords(in);
  101. }
  102.  
  103. //--Definition of output operator
  104. ostream & operator <<(ostream &out, WordInfo &word)
  105. {
  106. word.printWords(out);
  107. }
  108.  
  109. int main() {
  110. string wordFile;
  111. cout<<"enter name of dictionary file: ";
  112. getline (cin,wordFile);
  113.  
  114. ifstream inStream (wordFile.data());
  115.  
  116. if(!inStream.is_open())
  117. {
  118. cerr<<"cannot open "<<wordFile<<endl;
  119. exit(1);
  120. }
  121.  
  122. vector <WordInfo> wordVector;
  123. WordInfo aword;
  124.  
  125. while (inStream >>aword && (!(aword=="synonyms")))
  126. {
  127. wordVector.push_back(aword);
  128. }
  129.  
  130. inStream.clear(); // clears failbit on the ifstream
  131.  
  132. int i=0;
  133. while (i<wordVector.size()){
  134. cout<<wordVector[i]<<endl;
  135. i++;
  136. }
  137.  
  138. vector <int> intVector;
  139. string synLine; //suspect
  140.  
  141. while (getline(inStream, synLine)&&(synLine!=("antonyms"))){
  142. aword.pushSynonyms(synLine, wordVector);
  143. }
  144.  
  145. system("PAUSE");
  146. return 0;
  147. }
  148.  
  149. cout<<synsAux.size();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement