title: Handling Non-Ascii Chars in C++
body: <p>I am facing some issues with non-Ascii chars in C++. I have one file containg non-ascii chars which I am reading in C++ via file Handling. After reading the file(say 1.txt) I am storing the data into string stream and writing it into another file(say 2.txt).</p>
  
  <p>Assume 1.txt contains:</p>
  
  <pre><code>ação
  </code></pre>
  
  <p>In 2.txt I should get same ouyput but non-Ascii chars are printed as their Hex value in 2.txt.</p>
  
  <p>Also, I am quite sure that C++ is handling Ascii chars as Ascii only. </p>
  
  <p>Please Help on how to print these chars correctly in 2.txt</p>
  
  <p>EDIT:</p>
  
  <p>Firstly Psuedo-Code for Whole Process:</p>
  
  <pre><code>1.Shell script to Read from DB one Value and stores in 11.txt
  2.CPP Code(a.cpp) reading 11.txt and Writing to f.txt
  </code></pre>
  
  <p>Data Present in DB which is being read: <code>Instalação</code></p>
  
  <p>File 11.txt contains: <code>InstalaÃ§Ã£o</code></p>
  
  <p>File F.txt Contains: <code>InstalaÃ§Ã£o</code></p>
  
  <p>Ouput of a.cpp on screen: <code>Instalação</code></p>
  
  <p>a.cpp</p>
  
  <pre><code>#include &lt;iterator&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;sstream&gt;
  #include&lt;fstream&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  int main()
  {
      ifstream myReadFile;
      ofstream f2;
      myReadFile.open("11.txt");
      f2.open("f2.txt");
      string output;
      if (myReadFile.is_open()) 
      {
          while (!myReadFile.eof())
          {
              myReadFile &gt;&gt; output;
                  //cout&lt;&lt;output;
  
              cout&lt;&lt;"\n";
  
              std::stringstream tempDummyLineItem;
              tempDummyLineItem &lt;&lt;output;
              cout&lt;&lt;tempDummyLineItem.str();
              f2&lt;&lt;tempDummyLineItem.str();
          }
      }
      myReadFile.close();
      return 0;
  }
  </code></pre>
  
  <p>Locale says this:</p>
  
  <pre><code>LANG=en_US.UTF-8
  LC_CTYPE="en_US.UTF-8"
  LC_NUMERIC="en_US.UTF-8"
  LC_TIME="en_US.UTF-8"
  LC_COLLATE="en_US.UTF-8"
  LC_MONETARY="en_US.UTF-8"
  LC_MESSAGES="en_US.UTF-8"
  LC_PAPER="en_US.UTF-8"
  LC_NAME="en_US.UTF-8"
  LC_ADDRESS="en_US.UTF-8"
  LC_TELEPHONE="en_US.UTF-8"
  LC_MEASUREMENT="en_US.UTF-8"
  LC_IDENTIFICATION="en_US.UTF-8"
  LC_ALL=
  </code></pre>