title: C++ Add string to existing text file
body: <p>The code below makes a text file titled with the date and writes what was inputted on the command prompt onto the .txt. The problem is, Once I run the code a second time, it erases what was previously written and writes the newly inputted. If the text file already exists, I want to keep what was previously written, jump down two lines and add the new material. Any ideas?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;ctime&gt;
  
  void main()
  {
      time_t now = time(0);
      tm *ltm = localtime(&amp;now);
      int day = ltm-&gt;tm_mday;
      int month = 1 + ltm-&gt;tm_mon;
      int year = 1900 + ltm-&gt;tm_year;
      std::string d = std::to_string(day);
      std::string m = std::to_string(month);
      std::string y = std::to_string(year);
      std::string info;
      std::getline (std::cin, info); 
      std::ofstream notes(m + d + y + ".txt", std::ios::out);
      if (notes.is_open())
      {
          notes &lt;&lt; info;
      }
      else
      {
          std::cout &lt;&lt; "couldn't make file";
      }
  }
  </code></pre>