Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 18th, 2012  |  syntax: None  |  size: 1.19 KB  |  views: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void writeNumbers(vector<Integer*>& input)
  2.     {
  3.         ofstream write;
  4.         write.open("Integers.txt");
  5.         vector<Integer*>::iterator iter = input.begin();
  6.         for (iter; iter < input.end(); iter++)
  7.         {
  8.             **std::cout << (*iter)->toString() << std::endl;**
  9.         }
  10.         write.close();
  11.  
  12. I get an Access Violation error which points me to the toString() function:
  13.  
  14.     std::string Integer::toString()
  15.     {
  16.         std::stringstream ss;
  17.         ss << *(this)->value;
  18.         return ss.str();
  19.     }
  20.  
  21. toString() works fine whenever I don't try to access it through the iterator.
  22.        
  23. void writeNumbers(vector<Integer*>& input)
  24. {
  25.     ofstream write;
  26.     write.open("Integers.txt");
  27.     vector<Integer*>::iterator iter = input.begin();
  28.     for (iter; iter != input.end(); iter++)
  29.     {
  30.         std::cout << (*iter)->toString() << std::endl;
  31.     }
  32.     write.close();
  33. }
  34.        
  35. Integer::Integer(string input)
  36. {
  37. if(isNaN(input))
  38. value = new int(atoi(input.c_str()));
  39. }
  40.        
  41. //New constructor, works 100%
  42. Integer::Integer(string input)
  43. {
  44. if(!isNaN(input))
  45.     value = new int(atoi(input.c_str()));
  46. else
  47.     value = new int(0);
  48. }
  49.        
  50. ss << value;
  51.        
  52. iter < input.end()
  53.        
  54. iter != input.end()
clone this paste RAW Paste Data