title: How do you change the filename extension stored in a string in C++?
body: <p>Alright here's the deal, I'm taking an intro to C++ class at my university and am having trouble figuring out how to change the extension of a file. First, what we are suppose to do is read in a .txt file and count words, sentences, vowels etc. Well I got this but the next step is what's troubling me. We are then suppose to create a new file using the same file name as the input file but with the extension .code instead of .txt (in that new file we are then to encode the string by adding random numbers to the ASCII code of each character if you were interested). Being a beginner in programming, I'm not quite sure how to do this. I'm using the following piece of code to at first get the input file:</p>
  
  <pre><code>cout &lt;&lt; "Enter filename: ";
  cin &gt;&gt; filename;
  infile.open(filename.c_str());
  </code></pre>
  
  <p>I'm assuming to create a new file I'm going to be using something like:</p>
  
  <pre><code>outfile.open("test.code");
  </code></pre>
  
  <p>But I won't know what the file name is until the user enters it so I can't say "test.txt". So if anyone knows how to change that extenstion when I create a new file I would very much appreciate it!</p>