title: C++ to HTML conversion using namespaces
body: <p>I'm trying to convert a .cpp file into a .html file.</p>
  
  <p>Basically, at the end of the program, the html file when opened on chrome or whatever should look exactly like:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
      int main()
      {
          int x = 4;
          if (x &lt; 3) x++;
          cout &lt;&lt; x &lt;&lt; endl;
          return 0;
      }
  </code></pre>
  
  <p>I have three files, Source.cpp, fileToConvert.cpp, fileConverted.htm.</p>
  
  <p>Source.cpp:</p>
  
  <pre><code>//This program will convert the selected file to another file for example .cpp to .html file.
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  void conversion(ifstream&amp; inStream, ofstream&amp; outStream);
  
  
  
  
  int main()
  {
      ifstream fin;
      ofstream fout;
  
      cout &lt;&lt; "Begin editing files.\n";
  
      fin.open("fileToConvert.cpp"); //input file (must in the same folder)
      if (fin.fail())
      {
          cout &lt;&lt; "Input file opening failed.\n";
          exit(1);
      }
  
      fout.open("fileConverted.htm"); //output file (in the same folder)
      if (fout.fail())
      {
          cout &lt;&lt; "Output file opening failed.\n";
          exit(1);
      }
  
      fout &lt;&lt; "&lt;PRE&gt;" &lt;&lt; endl; //&lt;PRE&gt; is the tag for HTML file that will convert all the spacing according to the input file
  
      addPlusPlus(fin, fout);
  
      fout &lt;&lt; "&lt;/PRE&gt;" &lt;&lt; endl; //&lt;/PRE&gt; is the tag for HTML file that will close the &lt;PRE&gt; tag
  
      fin.close();
      fout.close();
  
      cout &lt;&lt; "End of editing files.\n";
      return 0;
  }
  
  
  
  
  
  void conversion(ifstream&amp; inStream, ofstream&amp; outStream)
  {
      char next;
  
      inStream.get(next);
  
      while (!inStream.eof())
      {
          if (next == '&lt;')
              outStream &lt;&lt; "&amp;lt;";
          else if (next == '&gt;')
              outStream &lt;&lt; "&amp;gt;";
          else
              outStream &lt;&lt; next;
  
          inStream.get(next);
      }
  
  }
  </code></pre>
  
  <p>fileToConvert.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
      int main()
      {
          int x = 4;
          if (x &lt; 3) x++;
          cout &lt;&lt; x &lt;&lt; endl;
          return 0;
      }
  </code></pre>
  
  <p>And then the output should look like the first block of code above as said <b>in HTML format</b>.</p>
  
  <p>The only way I can get this to work is to place the main() method in fileToConvert.cpp inside of a namespace, like so:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  namespace secondMain{
  
      int main()
      {
          int x = 4;
          if (x&lt;3) x++;
          cout &lt;&lt; x &lt;&lt; endl;
          return 0;
      }
  
  }
  </code></pre>
  
  <p>Problem obviously being, this will display the namespace secondMain{...} code inside of the .htm file and, which I do not want. </p>
  
  <p>If I don't use this second namespace, obviously the program will not work since there are two main() methods defined. </p>
  
  <p>What am I missing in this program? The only workaround I found was adding that second namespace, and I <b>do have to use namespaces in this project</b>, but cannot display that namespace definition in the html page.</p>
  
  <p>Any information is appreciated,
  Thanks!!</p>