title: C++ Taking data from a text file into int Vector
body: <p>I have an assignment from college where I have a text file with multiple values.
  They are on different lines and I have to take them and store them in a Vector.
  We also have to use a Class that has ifstream, ofstream and an int Vector already set up, but these are in the private section of the Class and I can not seem to use them (not allowed to change the class!).
  We took the values in via getline but now need to convert them from strings to int but the problem is that we are not allowed to add more libraries.
  The libraries we are allowed to use are:</p>
  
  <p><code>iostream</code>
  <code>string</code>
  <code>fstream</code>
  <code>vector</code></p>
  
  <p>Any help in converting these would be much appreciated!</p>
  
  <p>Here is the brief:</p>
  
  <blockquote>
    <p>Program 1</p>
    
    <p>Write a program that contains a class that meets the following
    declaration (i.e. this declaration should be put at the top of your
    cpp file):</p>
    
    <p>Your program should read sales values from a file called ‘sales.txt’
    and outputs a bar graph representing these values to a file called
    ‘graph.txt’. Create each bar in the bar graph by displaying a row of
    asterisks. Each asterisk should represent £100 of sales.</p>
    
    <p>For example, ‘sales.txt’ file contained these values: </p>
  
  <pre><code>1000
  500
  1200
  600
  200
  </code></pre>
    
    <p>Here is what the ‘graph.txt’ file should contain after the program is
    executed: </p>
  
  <pre><code>SALES BAR CHART
  (each * equals £100)
  Store 1: **********
  Store 2: *****
  Store 3: ************
  Store 4: ******
  Store 5: **
  </code></pre>
  </blockquote>
  
  <p>And here is the class we are not allowed to alter:</p>
  
  <pre><code>#pragma once
  #include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;fstream&gt;
  #include&lt;vector&gt;
  
  using namespace std;
  
  class SalesData
  {
  private:
  ifstream inputfile;
  ofstream outputfile;
  vector&lt;int&gt; salesrecords;
  public:
  void loadDataFromFile(string filename);
  void saveBarChartToFile(string filename);
  };
  </code></pre>
  
  <p>I have completely skipped the class now and created new ifstream/ofstream and vectors.
  The output I have working fine its the input that I am struggling with!</p>
  
  <pre><code>void loadDataFromFile()
  {
      ifstream inputfile;
      vector&lt;int&gt; salenumbers;
      int holder;
  
      inputfile.open("sales.txt");
  
      if (!inputfile.is_open())
      {
           cout &lt;&lt; "Text Not Open Error!";
      }
      else
      {
          string line;
          vector&lt;string&gt; text;
          int i = 0;
  
  
  
          while (inputfile.good())
          {
              getline(inputfile, line);
              text[i] = line;
              i++;
          }
          for (int z = 0; z &lt;= 5; z++)
          {
               int num = atoi(text.at(z).c_str());
               salenumbers.push_back(num);
          }
  
  
  
      }
      inputfile.close();
  
      saveBarChartToFile(salenumbers);
  }
  </code></pre>
  
  <p>I have tried multiple ways like til eof, just taking it straight into an int vector and they havent worked. I found many ways to change the string to an int but it required more libraries.</p>
  
  <p>Also if I could make use of the class it would make it easier.</p>
  
  <p>I was going to make a new question but it wont let me so adding it on to this one:</p>
  
  <p>I had a Function to output to a file that I was testing with cout and it was working fine printing to the screen. Now I have changed it to output to a file but nothing is coming up in the file.</p>
  
  <p>Was wondering if anyone could see the mistake:</p>
  
  <pre><code>void saveBarChartToFile(vector&lt;int&gt;numbers)
  {
      ofstream outputfile;
  
      outputfile.open("graph.txt", std::ios_base::app);
  
  
      if (!outputfile.is_open())
      {
          cout &lt;&lt; "FILE NOT OPEN ERROR!";
      }
      else
      {
          for (int i = 0; i &lt; numbers.size(); i++)
          {
              int stars = 0;
              int starAmount = numbers[i] / 100;
              outputfile &lt;&lt; "Shop" &lt;&lt; (i + 1) &lt;&lt; ":";
              for (int j = 0; j &lt; starAmount; j++)
              {
                  outputfile &lt;&lt; "*";
              }
              outputfile &lt;&lt; "/n";
          }
          outputfile.close();
      }
  }
  </code></pre>