Create a output file from file stream
<p>I am fairly new to c++ and yes this is a homework assignment.
I am considering a switch statement instead of the if else statements in my function.</p>

<p>I am trying to write information read from an input filestream, to an output file after the data has been manipulated.</p>

<p>The prgram is supposed to read information from a file, process it and then display the data on the console and also write the result to an output file, the program should ask the user to enter the filename for both input and output files.</p>

<p>I cannot get my program to create a file. It works with files that already exist though.</p>

<p>Please help me with getting my program to create a file if it does not exist.</p>

<p>Oh and this is in c++</p>

<p>Any help will be greatly appreciated.</p>

<p>MY CODE :</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;

using namespace std;

char getNumber(char l);

int main ()
{
     string s1 = "D:\\Unisa\\Assignment_stuffs\\COS1512\\Assignment\\";
     string inFile, outFile;

     cout &lt;&lt; " Please enter the input filename: ";
     cin &gt;&gt; inFile;
     cout &lt;&lt; "\nPlease enter the output filename: ";
     cin &gt;&gt; outFile;

     string inFileAdd = s1 + inFile;
     string inFileAdd2 = s1 + outFile;

     ifstream in_stream;
     ofstream out_stream;
     in_stream.open(inFileAdd.c_str(), ios::in);
     if (in_stream.fail())
     {
        cout &lt;&lt; "Error!! Input file opening failed.";
        exit(1);
     }
     out_stream.open(inFileAdd2.c_str(), ios::out);
     if (out_stream.fail())
     {
        cout &lt;&lt; "Error!! Output file opening failed.";
        exit(1);
     }   

     char next = ' ';
     string letter;

          while (!in_stream.eof()) 
          {
                in_stream.get(next);
                while (next != '\n')
                {
                        cout &lt;&lt; next;
                        out_stream.put(next);
                        letter = letter + getNumber(next);
                        in_stream.get(next); 
                }
               cout &lt;&lt; " " + letter;
               out_stream &lt;&lt; " " + letter &lt;&lt; endl;

               letter = "";
               cout &lt;&lt; endl;
          }


     in_stream.close();

    return 0;
}

char getNumber(char l)
{
     if ((l == 'A') || (l == 'a') || (l == 'B') || (l == 'b') || (l == 'C') || (l == 'c'))
     {
            return '2';
     }
     else if ((l == 'D') || (l == 'd') || (l == 'E') || (l == 'e') || (l == 'F') || (l == 'f'))
     {
          return '3';
     }
     else if ((l == 'G') || (l == 'g') || (l == 'H') || (l == 'h') || (l == 'I') || (l == 'i'))
     {
          return '4';
     }
     else if ((l == 'J') || (l == 'j') || (l == 'K') || (l == 'k') || (l == 'L') || (l == 'l'))
     {
          return '5';
     }
     else if ((l == 'M') || (l == 'm') || (l == 'N') || (l == 'n') || (l == 'O') || (l == 'o'))
     {
          return '6';
     }
     else if ((l == 'P') || (l == 'p') || (l == 'Q') || (l == 'q') || (l == 'R') || (l == 'r') || (l == 'S') || (l == 's'))
     {
          return '7';
     }
     else if ((l == 'T') || (l == 't') || (l == 'U') || (l == 'u') || (l == 'V') || (l == 'v'))
     {
          return '8';
     }
     else if ((l == 'W') || (l == 'w') || (l == 'X') || (l == 'x') || (l == 'Y') || (l == 'y') || (l == 'Z') || (l == 'z'))
     {
          return '9';
     }
}
</code></pre>
