title: How to read a Spanish encoded file and store it character by character?
body: <p>I have trouble reading a file and storing it on memory since it is written in Spanish, I think it could be an encoding problem. I would like to know a way to print or store each of the characters separately. I have already tried many things but the most accurate approach I have found is using the method <code>wstring readFile(const char* filename)</code>,as showed in the code:</p>
  
  <pre><code>#include &lt;sstream&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;algorithm&gt;
  
  std::wstring readFile(const char* filename)//Read using a file using wifstream
  {
      std::wifstream wif(filename);
  
      std::wstringstream wss;
  
      wss &lt;&lt; wif.rdbuf();
      return wss.str();
  }
  
  int main()
  {
      std::wstring fileContent = readFile("read.txt"); //Read file to wstring.
  
      std::wcout &lt;&lt; fileContent ; //Print the wstring. This works fine.
      std::cout &lt;&lt; " " &lt;&lt; std::endl;//Give spacing.
  
      wchar_t a; //create variable wchar_t.
      int fs = fileContent.size();
      std::cout &lt;&lt; "Number of chars: " &lt;&lt; fs; //Check content size.
  
      for (int i = 0; i &lt; fs; i++){ //I want to print each letter.
  
          a = fileContent.at(i);  //Assign to "a" content of specified index.
  
          std::wcout &lt;&lt; " " &lt;&lt; a ; //Print character stored in variable a.
      }
  }
  </code></pre>
  
  <p>It seems there is a problem when storing or printing the value of <code>fileContent.at(i)</code> or <code>fileContent[i]</code> in the variable <code>wchar_t a</code>. Do you know what could be improved in the code or give me a guideline to solve this problem?</p>
  
  <p>I am using Macintosh and Linux, if it helps to know.
  Thanks!</p>