title: Stringstream is outputting the correct data, but not extracing the correct data
body: <p>I was unlucky enough that his exact code was actually working for me. There is obviously some underlying problem that I am not seeing/understanding because it no longer works.</p>
  
  <p>This is what is happening:
  I am streaming data from a file, and when using the </p>
  
  <pre><code>buffer &gt;&gt; table_data;
  </code></pre>
  
  <p>As I output table_data each time, it is starting from the middle of the buffer.
  The tricky thing, If I output the buffer using</p>
  
  <pre><code>std::cout &lt;&lt; buffer.str();
  </code></pre>
  
  <p>That yields the correct data. So the stream buffer, has all of the right things, its just not going into table_data correctly.</p>
  
  <p>See full code block below.</p>
  
  <pre><code>    //read from table
      buffer &lt;&lt; table.rdbuf();
      buffer.clear(); 
  
      //clear table contents for rewrite later
      table.clear();
  
      std::ofstream table(filename);
  
      while (buffer &gt;&gt; table_data)
      {
          temp_vec.push_back(table_data);
  
          //num_table_items = 3, which is correct.
          for (int i = 1; i &lt; num_table_items; i++)
          {
              buffer &gt;&gt; table_data;
              temp_vec.push_back(table_data); 
          }
  
  
          //I removed the part where I write to the table from the vector because the problem is above.           
  
          temp_vec.clear();           
  
      }
  </code></pre>
  
  <p>if it matters, this is what the buffer is reading from the file:</p>
  
  <pre><code>1       'Gizmo'             19.99       
  2       'PowerGizmo'        29.99       
  3       'SingleTouch'       149.99      
  4       'MultiTouch'        199.99      
  5       'SuperGizmo'        49.99   
  </code></pre>
  
  <p>And thats what is printed when I do the std::cout &lt;&lt; buffer.str();
  however, if I print table data after both "buffer >> table_data" lines in the code, i get this (same results if I print the vector):</p>
  
  <pre><code>Gizmo'          29.99           3
  'SingleTouch'   149.99          4
  'MultiTouch'    199.99          5
  'SuperGizmo'    49.99           49.99
  </code></pre>
  
  <p>See how it starts in the middle? 'Gizmo' is even missing its first apostrophe. Any idea what is happening? Am i missing something obvious?</p>
  
  <p>**EDIT: Here is more code as requested. This is the if statement that eventually calls the function, the entire function, and the function declaration from my Table class. Thank you everyone for the help.</p>
  
  <pre><code>//Function definiton
  void update_table(std::string table_name, std::string table_path, std::string set_schema, std::string set_item, 
              std::string where_schema, std::string where_item);
  
  //From file that calls the function
  
  if (text == "DELETE" || text == "Delete" || text == "delete")
          {
              //skips "from"
              std::cin &gt;&gt; objName &gt;&gt; objName &gt;&gt; text;
  
              if (objName.back() == ';')
                  {
                      objName = objName.substr(0, objName.size()-1);
                  }
              if (text == "WHERE" || text == "Where" || text == "where")
              {
  
                  std::cin &gt;&gt; del_name &gt;&gt; operation &gt;&gt; del_param;
                  if (del_param.back() == ';')
                  {
                      del_param = del_param.substr(0, del_param.size()-1);
                  }
                  table.delete_table_data(objName, use_DB, del_name, operation, del_param);
              }
          }
  
  
  
  //The entire function
  void Table::update_table(std::string table_name, std::string table_path, std::string set_schema, std::string set_item,
      std::string where_schema, std::string where_item)
  {
      chdir(table_path.c_str());
  
      filename = table_name + ".txt";
      std::ifstream table (filename);
  
      //init counter
  
  
      if (table)
      {
          getline(table, table_data);
          table_info.str(table_data);
          table_info.clear();
          buffer &lt;&lt; table.rdbuf();
          buffer.clear();
          buffer.str();
  
          table.clear();
          //Unneccessary?
          table.close();
  
          std::ofstream table(filename);
  
  
  
          //Finds size of table, writes table labels back to file.
          num_table_items = 0;
  
          modify_count = 0;
  
          while(table_info &gt;&gt; item_name)
          {
              table_info &gt;&gt; item_type;
  
              table &lt;&lt; item_name &lt;&lt; " " &lt;&lt; item_type &lt;&lt; "\t\t";
  
              if (item_name == set_schema) // &amp;&amp; item_name == where_schema
              {
                  set_index = num_table_items;
              }
  
              if (item_name == where_schema)
              {
                  where_index = num_table_items;
              }
  
              num_table_items++;  
  
          }
  
          std::cout &lt;&lt; buffer.str() &lt;&lt; std::endl;
          while (getline(buffer, table_data))
          {
              std::cout &lt;&lt; table_data &lt;&lt; std::endl;
              temp_vec.push_back(table_data);
  
              for (int i = 1; i &lt; num_table_items; i++)
              {
                  buffer &gt;&gt; table_data;
                  std::cout &lt;&lt; "i = " &lt;&lt; i &lt;&lt; " Data = " &lt;&lt; table_data &lt;&lt; std::endl;
                  temp_vec.push_back(table_data);
  
              }
  
              if (temp_vec[where_index] == where_item)
              {
                  modify_count++;
                  temp_vec[set_index] = set_item;
              }                   
  
              //store in vector
              for (int i = 0; i &lt; temp_vec.size(); i++)
              {
                  table_vec.push_back(temp_vec[i]);
                  std::cout &lt;&lt; temp_vec[i] &lt;&lt; " ";
              }
  
              temp_vec.clear();           
  
          }
  
  
          for (int i = 0; i &lt; table_vec.size(); i++)
          {
              if (i % num_table_items == 0)
              {     
                  table &lt;&lt; "\n" &lt;&lt; table_vec[i] &lt;&lt; "\t";
              }
  
              else if (i % num_table_items == num_table_items - 1)
              {
                  table &lt;&lt; table_vec[i];
              }
  
              else
              {
                  table &lt;&lt; table_vec[i] &lt;&lt; "\t\t";
              }
  
              if (table_vec[i].length() &lt; 8 &amp;&amp; i % num_table_items != num_table_items - 1)
              {
                  table &lt;&lt; "\t";
              }
          }
  
          table.close();
          table_vec.clear();
          table_info.clear();
          table_info.str();
  
          //write vector to file.
          if (modify_count == 1)
          {
              std::cout &lt;&lt; "-- " &lt;&lt; modify_count &lt;&lt; " record modified." &lt;&lt; std::endl;
          }
  
          else
          {
              std::cout &lt;&lt; "-- " &lt;&lt; modify_count &lt;&lt; " records modified." &lt;&lt; std::endl;
          }
      }
  
      else
      {
          std:: cout &lt;&lt; "-- !Failed to query " &lt;&lt; table_name &lt;&lt; " because it does not exist" &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>the user input that should invoke this is:
  update Product
  set name = 'Gizmo'
  where name = 'SuperGizmo';</p>
  
  <p>or</p>
  
  <p>update Product set price = 14.99 where name = 'Gizmo';</p>