UNICODE I/O

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ali

    UNICODE I/O

    I would like to write a program that can handle non-ANSI characters.
    The following code does not work, the output is empty:

    #include <fstream>
    #include <string>
    using namespace std;

    int main() {
    wofstream out(L"log");
    if (!out)
    exit(127);
    wstring s(L"õûíÕÛÍ");
    out << s << endl;
    out.close();
    return 0;
    }

    The log file is in ANSI char encoding, and probably that is why the
    output fails.

    Could anyone help me how to do this?

    Many thanks.
  • Ali

    #2
    Re: UNICODE I/O

    Well, the example string L"õûíÕÛÍ" is not displayed correctly inmy
    previous e-mail (even though UTF-8 char encoding is used).

    Comment

    • Tobias Blomkvist

      #3
      Re: UNICODE I/O

      On Thu, 27 Mar 2008 05:12:14 -0700, Ali wrote:
      I would like to write a program that can handle non-ANSI characters. The
      following code does not work, the output is empty:
      >
      #include <fstream>
      #include <string>
      using namespace std;
      >
      int main() {
      wofstream out(L"log");
      if (!out)
      exit(127);
      wstring s(L"őűíŐŰà ");
      out << s << endl;
      out.close();
      return 0;
      }
      >
      The log file is in ANSI char encoding, and probably that is why the
      output fails.
      >
      Could anyone help me how to do this?
      >
      Remember that everything "wide" is not automatically unicode.
      Try saving the source file in utf-8 and open ordinary non-wide
      streams and output the string. Then you need to open the log
      file with a program that understands utf-8 and can display the
      actual characters.

      The following outputs correctly on my terminal when I save the
      source file as utf-8:

      #include <iostream>

      int main() {
      std::cout << "őűíŐŰ Í" << std::endl;
      return 0;
      }

      --
      Tobias Blomkvist

      Comment

      Working...