title: Writing and reading strange letters to a txt-file using libcurl
body: <p>I have a c++ program that downloads the HTML-code of a webpage and saves it as a  text file using the library LibCurl. The problem is, that we have the following strange letters in danish alphabet: Æ æ Ø ø Å å.
  When I try to read the HTML-code line by line, all these characters look like "�". I have tried to read/write the file as wide characters. That did not work.
  I have also tried to write a sentence containing "æ", "ø" og "å" to another text file and read it again. That, for some reason, worked.</p>
  
  <p>So my question is, why does the strange letters look like "�" when they are in the downloaded HTML-code but not when I write my own sentence? And how do I fix the HTML-output?</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include&lt;fstream&gt;
  #include&lt;curl/curl.h&gt;
  
  using namespace std;
  
  
  static size_t write_data (string * ptr, size_t size, size_t nmemb,void *stream)
  {
   size_t written = fwrite (ptr, size, nmemb, (FILE *) stream);
    cout &lt;&lt; static_cast &lt;const void *&gt; (ptr);
    return written;
    //string myString (ptr, nbytes);
  }
  //string myString (ptr, nbytes);
  int main ()
  {
  // Writing weird characters to a text-file!
  ofstream myfile;
  myfile.open ("example.txt");
  myfile &lt;&lt; "Print strange letter: æ ø og å!";
  myfile.close ();
  
  // Reading weird characters from the text-file!
  std::ifstream wif ("example.txt");
  if (wif.is_open ())
  {
    std::string wline;
    while (std::getline (wif, wline))
  {
    cout &lt;&lt; wline &lt;&lt; endl;
  
  }
  }
  else
  cout &lt;&lt; "Could not open file" &lt;&lt; endl ;
  wif.close ();
  
  cout &lt;&lt; endl &lt;&lt; endl;
  
  
  // Download the HTML-code from a webpage and save it.
  CURL *curl_handle;
  static const char *pagefilename = "example2.txt";
  const char *charUrl = "http://politiken.dk/forbrugogliv/sundhedogmotion/ECE3406716/mindst-85000-offentligt-ansatte-maa-slet-ikke-ryge-i-arbejdstiden/"; // An article from the danish newspaper "Politiken"
  
  FILE *pagefile;
  curl_global_init (CURL_GLOBAL_ALL);
  curl_handle = curl_easy_init ();
  curl_easy_setopt (curl_handle, CURLOPT_URL, charUrl);   // HERE IS THE URL PASSED!
  curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 0L);
  curl_easy_setopt (curl_handle, CURLOPT_NOPROGRESS, 0L);
  curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, write_data);
  pagefile = fopen (pagefilename, "wb");
  
  if (pagefile)
  {
    curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, pagefile);
    curl_easy_perform (curl_handle);
    fclose (pagefile);
  }
  curl_easy_cleanup (curl_handle);
  
  //Reading the HTML-code
  ifstream webIn ("example2.txt");
  if (webIn.is_open ())
  {
    std::string wline;
    while (getline (webIn, wline))
  {
    cout &lt;&lt; wline &lt;&lt; endl;
  }
  }
  else
  cout &lt;&lt; "Could not open example.txt" &lt;&lt; endl;
  
  
  
  return 0;
  }
  </code></pre>
  
  <p>And my output is </p>
  
  <pre><code>Print strange letter: æ ø og å!
  
  
  &gt;&gt;HTML-CODE CONTAINING "�" instead of æ ø å &lt;&lt;
  </code></pre>
  
  <p>I don't know if it is relevant, but my OS is Linux Mint 17.3 and I've set the language and region og my system to "English, Denmark UTF-8".</p>
  
  <p>Thanks in advance! I will really appreciate any help or hints :)</p>